namespace SmartSoft.Invoices
{
    using SmartSoft;
    using SmartSoft.Controls;
    using SmartSoft.Controls.ChildGridControls;
    using SmartSoft.ADP;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormCTKTEditor : FormEditor
    {
        private OptionColumn Column1;
        private DateColumn Column10;
        private SearchColumn Column11;
        private SearchColumn Column12;
        private DataGridViewTextBoxColumn Column13;
        private DataGridViewTextBoxColumn Column14;
        private SearchColumn Column2;
        private OptionColumn Column3;
        private NumericColumn Column4;
        private NumericColumn Column5;
        private NumericColumn Column6;
        private SearchColumn Column7;
        private SearchColumn Column8;
        private SearchColumn Column9;
        private IContainer components;
        public GridDetail grdDetail;
        private bool ib_RowExchangeType;
        private decimal ii_RowExchangeRateOfBook;
        private object is_CurrentRowCurrency;
        private LabelControl lblCt_Di_Kem;
        private LabelControl lblCt_Di_Kem0;
        private LabelControl lblDesc_EN;
        private LabelControl lblDia_Chi;
        private LabelControl lblDien_Giai;
        private LabelControl lblIL_TTien;
        private LabelControl lblMa_Bp;
        private LabelControl lblMa_Dt;
        private LabelControl lblMa_Hd;
        private LabelControl lblMa_Tte;
        private LabelControl lblOng_Ba;
        private LabelControl lblPs_Co_Nt;
        private LabelControl lblPs_No_Nt;
        private LabelControl lblUN_TTien;
        private CTKTDataAccess oMethod;
        private TextControl txtCt_Di_Kem;
        private TextControl txtDesc_EN;
        private TextControl txtDia_Chi;
        private TextControl txtDien_Giai;
        private TextNumeric txtIL_TTien;
        private TextSearch txtMa_Bp;
        private TextSearch txtMa_Dt;
        private TextSearch txtMa_Hd;
        private TextOption txtMa_Tte;
        private TextControl txtOng_Ba;
        private TextNumeric txtPs_Co;
        private TextNumeric txtPs_Co_Nt;
        private TextNumeric txtPs_No;
        private TextNumeric txtPs_No_Nt;
        private TextControl txtTen_Bp;
        private TextControl txtTen_Dt;
        private TextControl txtTen_Hd;
        private TextNumeric txtTy_Gia;
        private TextNumeric txtUN_TTien;

        public FormCTKTEditor()
        {
            this.oMethod = new CTKTDataAccess();
            this.is_CurrentRowCurrency = SDBNull.Value;
            this.ib_RowExchangeType = true;
            this.InitializeComponent();
            base.ToolStripFunctions = null;
            this.txtMa_Tte.InputMask = AppInstance.Currencies;
            this.Column3.InputMask = AppInstance.Currencies;
            base.DetailGridBrowser.CellEnter += new DataGridViewCellEventHandler(this.DetailGridBrowser_CellEnter);
            base.DetailGridBrowser.CellEndEdit += new DataGridViewCellEventHandler(this.DetailGridBrowser_CellEndEdit);
            base.DetailGridBrowser.CellValidating += new DataGridViewCellValidatingEventHandler(this.DetailGridBrowser_CellValidating);
            base.ResizeForm();
        }

        public FormCTKTEditor(SSInvoiceLib po_SSInvoiceLib) : base(po_SSInvoiceLib)
        {
            this.oMethod = new CTKTDataAccess();
            this.is_CurrentRowCurrency = SDBNull.Value;
            this.ib_RowExchangeType = true;
            this.InitializeComponent();
            base.ToolStripFunctions = null;
            base.InvoiceCode = po_SSInvoiceLib.InvoiceCode;
            this.txtMa_Tte.InputMask = AppInstance.Currencies;
            this.Column3.InputMask = AppInstance.Currencies;
            base.DetailGridBrowser.CellEnter += new DataGridViewCellEventHandler(this.DetailGridBrowser_CellEnter);
            base.DetailGridBrowser.CellEndEdit += new DataGridViewCellEventHandler(this.DetailGridBrowser_CellEndEdit);
            base.DetailGridBrowser.CellValidating += new DataGridViewCellValidatingEventHandler(this.DetailGridBrowser_CellValidating);
            base.ResizeForm();
        }

        public FormCTKTEditor(string ps_InvoiceCode, string ps_MasterInvoiceOrder) : base(ps_InvoiceCode, ps_MasterInvoiceOrder)
        {
            this.oMethod = new CTKTDataAccess();
            this.is_CurrentRowCurrency = SDBNull.Value;
            this.ib_RowExchangeType = true;
            this.InitializeComponent();
            base.ToolStripFunctions = null;
            base.InvoiceCode = ps_InvoiceCode;
            this.txtMa_Tte.InputMask = AppInstance.Currencies;
            this.Column3.InputMask = AppInstance.Currencies;
            base.DetailGridBrowser.CellEnter += new DataGridViewCellEventHandler(this.DetailGridBrowser_CellEnter);
            base.DetailGridBrowser.CellEndEdit += new DataGridViewCellEventHandler(this.DetailGridBrowser_CellEndEdit);
            base.DetailGridBrowser.CellValidating += new DataGridViewCellValidatingEventHandler(this.DetailGridBrowser_CellValidating);
            base.LocalMasterRow = this.oMethod.GetMasterDataRow(base.SavedMasterOrder);
            base.LocalDetailDataSet = this.oMethod.GetDetailDataSet(base.SavedMasterOrder);
            this.OnShow();
            base.ResizeForm();
        }

        public FormCTKTEditor(string ps_InvoiceCode, DateTime pd_Ngay_Ct, DataTable po_DepreciationTable)
        {
            this.oMethod = new CTKTDataAccess();
            this.is_CurrentRowCurrency = SDBNull.Value;
            this.ib_RowExchangeType = true;
            this.InitializeComponent();
            base.ToolStripFunctions = null;
            base.InvoiceCode = ps_InvoiceCode;
            this.txtMa_Tte.InputMask = AppInstance.Currencies;
            this.Column3.InputMask = AppInstance.Currencies;
            base.DetailGridBrowser.CellEnter += new DataGridViewCellEventHandler(this.DetailGridBrowser_CellEnter);
            base.DetailGridBrowser.CellEndEdit += new DataGridViewCellEventHandler(this.DetailGridBrowser_CellEndEdit);
            base.DetailGridBrowser.CellValidating += new DataGridViewCellValidatingEventHandler(this.DetailGridBrowser_CellValidating);
            this.CreateDepreciation(pd_Ngay_Ct, po_DepreciationTable);
            this.OnShow();
            base.ResizeForm();
        }

        private bool AddNewRow()
        {
            if ((base.DetailGridBrowser.CurrentRow == null) || (base.DetailGridBrowser.CurrentRow.DataBoundItem == null))
            {
                return false;
            }
            DataRow row = ((DataRowView) base.DetailGridBrowser.CurrentRow.DataBoundItem).Row;
            if (((((decimal) row["Tien_Nt"]) + ((decimal) row["Tien"])) == 0M) || string.IsNullOrEmpty(row["Tk"].ToString()))
            {
                return false;
            }
            int num = 0;
            int num2 = 0;
            int num3 = 0;
            int num4 = 0;
            int num5 = 0;
            int num6 = 0;
            int num7 = (int) row["Stt_Nv"];
            string str = row["No_Co"].ToString();
            foreach (DataRow row2 in base.LocalDetailTable.Rows)
            {
                if ((row2.RowState != DataRowState.Deleted) && (((int) row2["Stt_Nv"]) > num))
                {
                    num = (int) row2["Stt_Nv"];
                }
            }
            if (str == "N")
            {
                num2 = 0;
                num3 = num7;
                foreach (DataRow row3 in base.LocalDetailTable.Rows)
                {
                    if (((row3.RowState != DataRowState.Deleted) && (row3["No_Co"].ToString() == "C")) && ((((int) row3["Stt_Nv"]) < num7) && (((int) row3["Stt_Nv"]) > num2)))
                    {
                        num2 = (int) row3["Stt_Nv"];
                    }
                }
                if (num2 == 0)
                {
                    foreach (DataRow row4 in base.LocalDetailTable.Rows)
                    {
                        if (((row4.RowState != DataRowState.Deleted) && (row4["No_Co"].ToString() == "N")) && ((((int) row4["Stt_Nv"]) <= num7) && (((int) row4["Stt_Nv"]) < num3)))
                        {
                            num3 = (int) row4["Stt_Nv"];
                        }
                    }
                }
                else
                {
                    foreach (DataRow row5 in base.LocalDetailTable.Rows)
                    {
                        if (((row5.RowState != DataRowState.Deleted) && (row5["No_Co"].ToString() == "N")) && ((((int) row5["Stt_Nv"]) > num2) && (((int) row5["Stt_Nv"]) < num3)))
                        {
                            num3 = (int) row5["Stt_Nv"];
                        }
                    }
                }
                num2 = 0x7fffffff;
                foreach (DataRow row6 in base.LocalDetailTable.Rows)
                {
                    if (((row6.RowState != DataRowState.Deleted) && (row6["No_Co"].ToString() == "C")) && ((((int) row6["Stt_Nv"]) > num7) && (((int) row6["Stt_Nv"]) < num2)))
                    {
                        num2 = (int) row6["Stt_Nv"];
                    }
                }
                if (num2 == 0x7fffffff)
                {
                    num4 = 0;
                    foreach (DataRow row7 in base.LocalDetailTable.Rows)
                    {
                        if (((row7.RowState != DataRowState.Deleted) && (row7["No_Co"].ToString() == "N")) && ((((int) row7["Stt_Nv"]) >= num7) && (((int) row7["Stt_Nv"]) > num4)))
                        {
                            num4 = (int) row7["Stt_Nv"];
                        }
                    }
                }
                else
                {
                    num5 = num2;
                    num4 = 0;
                    foreach (DataRow row8 in base.LocalDetailTable.Rows)
                    {
                        if (((row8.RowState != DataRowState.Deleted) && (row8["No_Co"].ToString() == "N")) && ((((int) row8["Stt_Nv"]) < num2) && (((int) row8["Stt_Nv"]) > num4)))
                        {
                            num4 = (int) row8["Stt_Nv"];
                        }
                    }
                    num2 = 0x7fffffff;
                    foreach (DataRow row9 in base.LocalDetailTable.Rows)
                    {
                        if (((row9.RowState != DataRowState.Deleted) && (row9["No_Co"].ToString() == "N")) && ((((int) row9["Stt_Nv"]) > num5) && (((int) row9["Stt_Nv"]) < num2)))
                        {
                            num2 = (int) row9["Stt_Nv"];
                        }
                    }
                    if (num2 == 0x7fffffff)
                    {
                        foreach (DataRow row10 in base.LocalDetailTable.Rows)
                        {
                            if (((row10.RowState != DataRowState.Deleted) && (row10["No_Co"].ToString() == "C")) && (((int) row10["Stt_Nv"]) > num6))
                            {
                                num6 = (int) row10["Stt_Nv"];
                            }
                        }
                    }
                    else
                    {
                        foreach (DataRow row11 in base.LocalDetailTable.Rows)
                        {
                            if (((row11.RowState != DataRowState.Deleted) && (row11["No_Co"].ToString() == "C")) && ((((int) row11["Stt_Nv"]) < num2) && (((int) row11["Stt_Nv"]) > num6)))
                            {
                                num6 = (int) row11["Stt_Nv"];
                            }
                        }
                    }
                }
            }
            else
            {
                num2 = 0;
                num3 = 0x7fffffff;
                int num8 = 0;
                foreach (DataRow row12 in base.LocalDetailTable.Rows)
                {
                    if (((row12.RowState != DataRowState.Deleted) && (row12["No_Co"].ToString() == "N")) && ((((int) row12["Stt_Nv"]) < num7) && (((int) row12["Stt_Nv"]) > num8)))
                    {
                        num8 = (int) row12["Stt_Nv"];
                    }
                }
                foreach (DataRow row13 in base.LocalDetailTable.Rows)
                {
                    if (((row13.RowState != DataRowState.Deleted) && (row13["No_Co"].ToString() == "C")) && ((((int) row13["Stt_Nv"]) < num8) && (((int) row13["Stt_Nv"]) > num2)))
                    {
                        num2 = (int) row13["Stt_Nv"];
                    }
                }
                if (num2 == 0)
                {
                    foreach (DataRow row14 in base.LocalDetailTable.Rows)
                    {
                        if (((row14.RowState != DataRowState.Deleted) && (row14["No_Co"].ToString() == "N")) && ((((int) row14["Stt_Nv"]) <= num7) && (((int) row14["Stt_Nv"]) < num3)))
                        {
                            num3 = (int) row14["Stt_Nv"];
                        }
                    }
                }
                else
                {
                    foreach (DataRow row15 in base.LocalDetailTable.Rows)
                    {
                        if (((row15.RowState != DataRowState.Deleted) && (row15["No_Co"].ToString() == "N")) && ((((int) row15["Stt_Nv"]) > num2) && (((int) row15["Stt_Nv"]) < num3)))
                        {
                            num3 = (int) row15["Stt_Nv"];
                        }
                    }
                }
                num2 = 0x7fffffff;
                foreach (DataRow row16 in base.LocalDetailTable.Rows)
                {
                    if (((row16.RowState != DataRowState.Deleted) && (row16["No_Co"].ToString() == "C")) && ((((int) row16["Stt_Nv"]) > num3) && (((int) row16["Stt_Nv"]) < num2)))
                    {
                        num2 = (int) row16["Stt_Nv"];
                    }
                }
                num5 = num2;
                num4 = 0;
                foreach (DataRow row17 in base.LocalDetailTable.Rows)
                {
                    if (((row17.RowState != DataRowState.Deleted) && (row17["No_Co"].ToString() == "N")) && ((((int) row17["Stt_Nv"]) < num2) && (((int) row17["Stt_Nv"]) > num4)))
                    {
                        num4 = (int) row17["Stt_Nv"];
                    }
                }
                num2 = 0x7fffffff;
                foreach (DataRow row18 in base.LocalDetailTable.Rows)
                {
                    if (((row18.RowState != DataRowState.Deleted) && (row18["No_Co"].ToString() == "N")) && ((((int) row18["Stt_Nv"]) > num5) && (((int) row18["Stt_Nv"]) < num2)))
                    {
                        num2 = (int) row18["Stt_Nv"];
                    }
                }
                if (num2 == 0x7fffffff)
                {
                    foreach (DataRow row19 in base.LocalDetailTable.Rows)
                    {
                        if (((row19.RowState != DataRowState.Deleted) && (row19["No_Co"].ToString() == "C")) && (((int) row19["Stt_Nv"]) > num6))
                        {
                            num6 = (int) row19["Stt_Nv"];
                        }
                    }
                }
                else
                {
                    foreach (DataRow row20 in base.LocalDetailTable.Rows)
                    {
                        if (((row20.RowState != DataRowState.Deleted) && (row20["No_Co"].ToString() == "C")) && ((((int) row20["Stt_Nv"]) < num2) && (((int) row20["Stt_Nv"]) > num6)))
                        {
                            num6 = (int) row20["Stt_Nv"];
                        }
                    }
                }
            }
            decimal num9 = 0M;
            decimal d = 0M;
            decimal num11 = 0M;
            decimal num12 = 0M;
            foreach (DataRow row21 in base.LocalDetailTable.Rows)
            {
                if (row21.RowState != DataRowState.Deleted)
                {
                    if (((row21["No_Co"].ToString() == "N") && (((int) row21["Stt_Nv"]) >= num3)) && (((int) row21["Stt_Nv"]) <= num4))
                    {
                        num9 += (decimal) row21["Tien_Nt"];
                        d += (decimal) row21["Tien"];
                    }
                    if (((row21["No_Co"].ToString() == "C") && (((int) row21["Stt_Nv"]) >= num5)) && (((int) row21["Stt_Nv"]) <= num6))
                    {
                        num11 += (decimal) row21["Tien_Nt"];
                        num12 += (decimal) row21["Tien"];
                    }
                }
            }
            bool flag = false;
            bool flag2 = false;
            int key = 0;
            //decimal num14 = (d > 0M) ? d : decimal.op_UnaryNegation(d);
            decimal num14 = (d > 0M) ? d : -d;
            //decimal num15 = (num12 > 0M) ? num12 : decimal.op_UnaryNegation(num12);
            decimal num15 = (num12 > 0M) ? num12 : -num12;
            if (num14 > num15)
            {
                flag2 = true;
                flag = true;
                key = ((num4 > num6) ? num4 : num6) + 1;
                str = "C";
            }
            else if ((num14 == num15) && (num7 == num))
            {
                flag2 = true;
                key = num + 1;
                str = "N";
            }
            else if ((num14 < num15) && (num7 == num6))
            {
                return true;
            }
            if (!flag2)
            {
                return false;
            }
            if (flag)
            {
                foreach (DataRow row22 in base.LocalDetailTable.Rows)
                {
                    if ((row22.RowState != DataRowState.Deleted) && (((int) row22["Stt_Nv"]) >= key))
                    {
                        row22["Stt_Nv"] = ((int) row22["Stt_Nv"]) + 1;
                    }
                }
            }
            base.DetailGridBrowser.EndEdit();
            DataRow row23 = base.MakeDetailRow();
            if (base.SSInvoiceParameters.DefaultActivate == str)
            {
                row23["Tk"] = base.SSInvoiceParameters.DefaultAccountCode;
            }
            this.UpdateTkParameters(row23, false);
            row23["Stt_Nv"] = key;
            row23["No_Co"] = str;
            row23["Tien_Nt"] = num9 - num11;
            row23["Tien"] = d - num12;
            row23["Ma_Tte"] = this.txtMa_Tte.Value;
            row23["Ty_Gia"] = this.txtTy_Gia.Value;
            row23["Ty_Gia_Ht"] = this.txtTy_Gia.Value;
            row23["Dien_Giai"] = this.txtDien_Giai.Value;
            row23["Desc_EN"] = this.txtDesc_EN.Value;
            if (base.SSInvoiceParameters.DefaultActivate == str)
            {
                row23["Tk"] = base.SSInvoiceParameters.DefaultAccountCode;
            }
            base.LocalDetailTable.Rows.Add(row23);
            BindingSource dataSource = base.DetailGridBrowser.DataSource as BindingSource;
            dataSource.Position = dataSource.Find(base.DetailOrderString, key);
            return true;
        }

        private void Calculate(DataRow po_Row)
        {
            if (DBNull.Value.Equals(po_Row["Tien_Nt"]))
            {
                po_Row["Tien_Nt"] = 0;
            }
            if (DBNull.Value.Equals(po_Row["Tien"]))
            {
                po_Row["Tien"] = 0;
            }
            if (po_Row["Ma_Tte"].ToString() == AppInstance.DefaultCurrency)
            {
                po_Row["Tien"] = decimal.Round(((decimal) po_Row["Tien_Nt"]) * this.RowExchangeRateOfBook, AppInstance.LCAmountDecimals);
            }
            else if (((decimal) po_Row["Tien"]) == 0M)
            {
                if (this.RowExchangeType)
                {
                    po_Row["Tien"] = decimal.Round(((decimal) po_Row["Tien_Nt"]) * this.RowExchangeRateOfBook, AppInstance.LCAmountDecimals);
                }
                else
                {
                    po_Row["Tien"] = decimal.Round(((decimal) po_Row["Tien_Nt"]) / this.RowExchangeRateOfBook, AppInstance.LCAmountDecimals);
                }
            }
            else if (this.RowExchangeType)
            {
                if (((((decimal) po_Row["Tien_Nt"]) != 0M) && (((decimal) po_Row["Ty_Gia"]) != 1M)) && ((((decimal) po_Row["Tien"]) < (decimal.Round(((decimal) po_Row["Tien_Nt"]) * this.RowExchangeRateOfBook, AppInstance.LCAmountDecimals) - AppInstance.AmountRange)) || (((decimal) po_Row["Tien"]) > (decimal.Round(((decimal) po_Row["Tien_Nt"]) * this.RowExchangeRateOfBook, AppInstance.LCAmountDecimals) + AppInstance.AmountRange))))
                {
                    po_Row["Tien"] = decimal.Round(((decimal) po_Row["Tien_Nt"]) * this.RowExchangeRateOfBook, AppInstance.LCAmountDecimals);
                }
            }
            else if (((((decimal) po_Row["Tien_Nt"]) != 0M) && (((decimal) po_Row["Ty_Gia"]) != 1M)) && ((((decimal) po_Row["Tien"]) < (decimal.Round(((decimal) po_Row["Tien_Nt"]) / this.RowExchangeRateOfBook, AppInstance.LCAmountDecimals) - AppInstance.AmountRange)) || (((decimal) po_Row["Tien"]) > (decimal.Round(((decimal) po_Row["Tien_Nt"]) / this.RowExchangeRateOfBook, AppInstance.LCAmountDecimals) + AppInstance.AmountRange))))
            {
                po_Row["Tien"] = decimal.Round(((decimal) po_Row["Tien_Nt"]) / this.RowExchangeRateOfBook, AppInstance.LCAmountDecimals);
            }
            po_Row.EndEdit();
        }

        private void CreateDepreciation(DateTime pd_Ngay_Ct, DataTable po_DepreciationTable)
        {
            DataRow row;
            base.LocalMasterRow = this.oMethod.GetMasterDataRow("SSSOFT2009");
            base.LocalDetailDataSet = this.oMethod.GetDetailDataSet("SSSOFT2009");
            this.OnAdd();
            base.LocalMasterRow["Ngay_Ps"] = pd_Ngay_Ct;
            base.LocalMasterRow["Ngay_Ct"] = pd_Ngay_Ct;
            DataTable table = new DataTable();
            DataColumn column = new DataColumn("Tk_No", typeof(string));
            table.Columns.Add(column);
            column = new DataColumn("Tk_Co", typeof(string));
            table.Columns.Add(column);
            column = new DataColumn("Ma_Bp", typeof(string));
            table.Columns.Add(column);
            column = new DataColumn("Ma_Km", typeof(string));
            table.Columns.Add(column);
            column = new DataColumn("Ma_Sp", typeof(string));
            table.Columns.Add(column);
            column = new DataColumn("Tien", typeof(decimal));
            table.Columns.Add(column);
            table.PrimaryKey = new DataColumn[] { table.Columns[0], table.Columns[1], table.Columns[2], table.Columns[3], table.Columns[4] };
            foreach (DataRow row2 in po_DepreciationTable.Rows)
            {
                if (row2.RowState != DataRowState.Deleted)
                {
                    object[] keys = new object[] { row2["Tk_No"], row2["Tk_Co"], row2["Ma_Bp"], row2["Ma_Km"], row2["Ma_Sp"] };
                    row = table.Rows.Find(keys);
                    if (row != null)
                    {
                        row["Tien"] = (((((decimal) row["Tien"]) + ((decimal) row2["Tien2_N1"])) + ((decimal) row2["Tien2_N2"])) + ((decimal) row2["Tien2_N3"])) + ((decimal) row2["Tien2_N4"]);
                    }
                    else
                    {
                        row = table.NewRow();
                        row["Tk_No"] = row2["Tk_No"];
                        row["Tk_Co"] = row2["Tk_Co"];
                        row["Ma_Bp"] = row2["Ma_Bp"];
                        row["Ma_Km"] = row2["Ma_Km"];
                        row["Ma_Sp"] = row2["Ma_Sp"];
                        row["Tien"] = ((((decimal) row2["Tien2_N1"]) + ((decimal) row2["Tien2_N2"])) + ((decimal) row2["Tien2_N3"])) + ((decimal) row2["Tien2_N4"]);
                        table.Rows.Add(row);
                    }
                }
            }
            if (table.Rows.Count > 0)
            {
                decimal num = 0M;
                int num2 = 0;
                base.LocalDetailTable.Rows.Clear();
                foreach (DataRow row3 in table.Rows)
                {
                    if (row3.RowState != DataRowState.Deleted)
                    {
                        num += (decimal) row3["Tien"];
                        num2++;
                        row = base.MakeDetailRow();
                        row["Stt_Nv"] = num2;
                        row["No_Co"] = "N";
                        row["Tk"] = row3["Tk_No"];
                        row["Ma_Tte"] = AppInstance.DefaultCurrency;
                        row["Ty_Gia"] = 1;
                        row["Ty_Gia_Ht"] = 1;
                        row["Tien_Nt"] = row3["Tien"];
                        row["Tien"] = row3["Tien"];
                        row["Ma_Bp"] = row3["Ma_Bp"];
                        row["Ma_Km"] = row3["Ma_Km"];
                        row["Ma_Sp"] = row3["Ma_Sp"];
                        this.UpdateTkParameters(row, false);
                        base.LocalDetailTable.Rows.Add(row);
                        num2++;
                        row = base.MakeDetailRow();
                        row["Stt_Nv"] = num2;
                        row["No_Co"] = "C";
                        row["Tk"] = row3["Tk_Co"];
                        row["Ma_Tte"] = AppInstance.DefaultCurrency;
                        row["Ty_Gia"] = 1;
                        row["Ty_Gia_Ht"] = 1;
                        row["Tien_Nt"] = row3["Tien"];
                        row["Tien"] = row3["Tien"];
                        row["Ma_Bp"] = row3["Ma_Bp"];
                        row["Ma_Km"] = row3["Ma_Km"];
                        row["Ma_Sp"] = row3["Ma_Sp"];
                        this.UpdateTkParameters(row, false);
                        base.LocalDetailTable.Rows.Add(row);
                    }
                }
                base.LocalMasterRow["TTien_NtN"] = num;
                base.LocalMasterRow["TTien_NtC"] = num;
                base.LocalMasterRow["TTien"] = num;
            }
        }

        private void DetailGridBrowser_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (((e.ColumnIndex == 1) || (e.ColumnIndex == 2)) || (((e.ColumnIndex == 3) || (e.ColumnIndex == 4)) || (e.ColumnIndex == 5)))
            {
                DataRow row = ((DataRowView) base.DetailGridBrowser.CurrentRow.DataBoundItem).Row;
                if ((e.ColumnIndex == 2) || (e.ColumnIndex == 4))
                {
                    if (e.ColumnIndex == 2)
                    {
                        this.CurrentRowCurrency = row["Ma_Tte"];
                        row["Ty_Gia"] = this.RowExchangeRateOfBook;
                    }
                    else
                    {
                        this.RowExchangeRateOfBook = (decimal) row["Ty_Gia"];
                    }
                    row["Ty_Gia_Ht"] = decimal.Round(this.RowExchangeRate, base.ExchangeDecimals);
                }
                else
                {
                    this.RowExchangeRateOfBook = (decimal) row["Ty_Gia"];
                }
                this.Calculate(row);
                this.Sum();
                if (e.ColumnIndex == 1)
                {
                    this.UpdateTkParameters(row, false);
                }
            }
        }

        private void DetailGridBrowser_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            if ((base.DetailGridBrowser.CurrentRow != null) && (base.DetailGridBrowser.CurrentRow.DataBoundItem != null))
            {
                DataRow row = ((DataRowView) base.DetailGridBrowser.CurrentRow.DataBoundItem).Row;
                if (e.ColumnIndex == 1)
                {
                    string str = "";
                    base.SSInvoiceParameters.MakeAmountWarningMessage(true, base.LocalMasterRow["Posted"], base.SavedMasterOrder, row["Stt0"], base.txtNgay_Ct.Value, row["Tk"], SDBNull.Value, base.LocalDetailTable, ref str);
                    base.WarningMessage = str;
                }
                else if (e.ColumnIndex == 8)
                {
                    string str2 = "";
                    base.SSInvoiceParameters.MakeAmountWarningMessage(true, base.LocalMasterRow["Posted"], base.SavedMasterOrder, row["Stt0"], base.txtNgay_Ct.Value, SDBNull.Value, row["Ma_Dt"], base.LocalDetailTable, ref str2);
                    base.WarningMessage = str2;
                }
                if (e.ColumnIndex == 5)
                {
                    if (row["Ma_Tte"].Equals(AppInstance.DefaultCurrency))
                    {
                        ((DataGridView) sender)[e.ColumnIndex, e.RowIndex].ReadOnly = true;
                    }
                    else
                    {
                        ((DataGridView) sender)[e.ColumnIndex, e.RowIndex].ReadOnly = false;
                    }
                }
                if (e.ColumnIndex == 6)
                {
                    if (!row["Tk_BP"].Equals("C"))
                    {
                        row["Ma_Bp"] = SDBNull.Value;
                        row["Ten_Bp"] = SDBNull.Value;
                        ((DataGridView) sender)[e.ColumnIndex, e.RowIndex].ReadOnly = true;
                    }
                    else
                    {
                        ((DataGridView) sender)[e.ColumnIndex, e.RowIndex].ReadOnly = false;
                    }
                }
                if (e.ColumnIndex == 7)
                {
                    if (!row["Tk_HD"].Equals("C"))
                    {
                        row["Ma_Hd"] = SDBNull.Value;
                        row["Ten_Hd"] = SDBNull.Value;
                        ((DataGridView) sender)[e.ColumnIndex, e.RowIndex].ReadOnly = true;
                    }
                    else
                    {
                        ((DataGridView) sender)[e.ColumnIndex, e.RowIndex].ReadOnly = false;
                    }
                }
                if (e.ColumnIndex == 8)
                {
                    if (!row["Tk_DT"].Equals("C"))
                    {
                        row["Ma_Dt"] = SDBNull.Value;
                        row["Ten_Dt"] = SDBNull.Value;
                        ((DataGridView) sender)[e.ColumnIndex, e.RowIndex].ReadOnly = true;
                    }
                    else
                    {
                        ((DataGridView) sender)[e.ColumnIndex, e.RowIndex].ReadOnly = false;
                    }
                }
                if (e.ColumnIndex == 9)
                {
                    if (!row["Tk_Dt"].Equals("C") && !row["Tk_Kv"].Equals("C"))
                    {
                        row["Han_Tt"] = DBNull.Value;
                        ((DataGridView) sender)[e.ColumnIndex, e.RowIndex].ReadOnly = true;
                    }
                    else
                    {
                        ((DataGridView) sender)[e.ColumnIndex, e.RowIndex].ReadOnly = false;
                    }
                }
                if (e.ColumnIndex == 10)
                {
                    if (!row["Tk_KM"].Equals("C"))
                    {
                        row["Ma_Km"] = SDBNull.Value;
                        row["Ten_Km"] = SDBNull.Value;
                        ((DataGridView) sender)[e.ColumnIndex, e.RowIndex].ReadOnly = true;
                    }
                    else
                    {
                        ((DataGridView) sender)[e.ColumnIndex, e.RowIndex].ReadOnly = false;
                    }
                }
                if (e.ColumnIndex == 11)
                {
                    if (!row["Tk_GT"].Equals("C"))
                    {
                        row["Ma_Sp"] = SDBNull.Value;
                        row["Ten_Sp"] = SDBNull.Value;
                        ((DataGridView) sender)[e.ColumnIndex, e.RowIndex].ReadOnly = true;
                    }
                    else
                    {
                        ((DataGridView) sender)[e.ColumnIndex, e.RowIndex].ReadOnly = false;
                    }
                }
            }
        }

        private void DetailGridBrowser_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            if ((base.DetailGridBrowser.CurrentRow != null) && (base.DetailGridBrowser.CurrentRow.DataBoundItem != null))
            {
                string str = "";
                DataRow row = ((DataRowView) base.DetailGridBrowser.CurrentRow.DataBoundItem).Row;
                if ((e.ColumnIndex == 1) || (e.ColumnIndex == 8))
                {
                    if (((e.ColumnIndex == 1) && string.IsNullOrEmpty(e.FormattedValue.ToString())) && (((decimal) row["Tien_Nt"]) != 0M))
                    {
                        e.Cancel = true;
                        (base.DetailGridBrowser.CurrentCell as SearchCell).CheckMovable = false;
                        return;
                    }
                    e.Cancel = false;
                    (base.DetailGridBrowser.CurrentCell as SearchCell).CheckMovable = true;
                }
                if (((e.ColumnIndex == 8) || (e.ColumnIndex == 3)) && ((AppInstance.DebitWarning != 0) && row["Tk_DT"].Equals("C")))
                {
                    if (e.ColumnIndex == 3)
                    {
                        if (base.DetailGridBrowser.CurrentCell.IsInEditMode)
                        {
                            row["Tien_Nt"] = Convert.ToDecimal(string.IsNullOrEmpty(e.FormattedValue.ToString()) ? "0" : e.FormattedValue);
                            this.Calculate(row);
                        }
                        if (((AppInstance.DebitWarning != 0) && (((decimal) row["Tien_Nt"]) != 0M)) && !base.SSInvoiceParameters.MakeAmountWarningMessage(false, base.LocalMasterRow["Posted"], base.SavedMasterOrder, row["Stt0"], base.txtNgay_Ct.Value, SDBNull.Value, row["Ma_Dt"], base.LocalDetailTable, ref str))
                        {
                            if (AppInstance.DebitWarning == 2)
                            {
                                e.Cancel = true;
                                (base.DetailGridBrowser.CurrentCell as NumericCell).CheckMovable = false;
                            }
                            else
                            {
                                e.Cancel = false;
                                (base.DetailGridBrowser.CurrentCell as NumericCell).CheckMovable = true;
                            }
                            MessageBox.Show(str, AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                        }
                    }
                    else if (((e.ColumnIndex == 8) && (((decimal) row["Tien_Nt"]) != 0M)) && (!base.SSInvoiceParameters.MakeAmountWarningMessage(false, base.LocalMasterRow["Posted"], base.SavedMasterOrder, row["Stt0"], base.txtNgay_Ct.Value, SDBNull.Value, e.FormattedValue, base.LocalDetailTable, ref str) && (AppInstance.DebitWarning != 0)))
                    {
                        if (AppInstance.DebitWarning == 2)
                        {
                            e.Cancel = true;
                            (base.DetailGridBrowser.CurrentCell as SearchCell).CheckMovable = false;
                        }
                        else
                        {
                            e.Cancel = false;
                            (base.DetailGridBrowser.CurrentCell as SearchCell).CheckMovable = true;
                        }
                        MessageBox.Show(str, AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    }
                }
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void grdDetail_CellBottomLeftLeaved(object sender, EventArgs e)
        {
            if (((base.DetailGridBrowser.Rows.Count == 1) || !string.IsNullOrEmpty(((DataRowView) base.DetailGridBrowser.CurrentRow.DataBoundItem).Row["Tk"].ToString())) || !string.IsNullOrEmpty(base.ActiveControl.Text))
            {
                base.DetailGridBrowser.EndEdit();
                (base.DetailGridBrowser as GridDetail).UserMoveNextCell = GridDetail.MoveNextType.NextCell;
            }
            else if (this.Sum())
            {
                this.txtIL_TTien.Focus();
                (base.DetailGridBrowser as GridDetail).UserMoveNextCell = GridDetail.MoveNextType.DeleteCurrentRow;
            }
        }

        private void grdDetail_CellRightLeaved(object sender, EventArgs e)
        {
            if (this.AddNewRow())
            {
                (base.DetailGridBrowser as GridDetail).UserMoveNextCell = GridDetail.MoveNextType.FirstCell;
            }
            else
            {
                (base.DetailGridBrowser as GridDetail).UserMoveNextCell = GridDetail.MoveNextType.FirstCellNextRow;
            }
        }

        private void InitializeComponent()
        {
            //ComponentResourceManager manager = new ComponentResourceManager(typeof(FormCTKTEditor));
            DataGridViewCellStyle style = new DataGridViewCellStyle();
            DataGridViewCellStyle style2 = new DataGridViewCellStyle();
            DataGridViewCellStyle style3 = new DataGridViewCellStyle();
            DataGridViewCellStyle style4 = new DataGridViewCellStyle();
            DataGridViewCellStyle style5 = new DataGridViewCellStyle();
            DataGridViewCellStyle style6 = new DataGridViewCellStyle();
            DataGridViewCellStyle style7 = new DataGridViewCellStyle();
            DataGridViewCellStyle style8 = new DataGridViewCellStyle();
            DataGridViewCellStyle style9 = new DataGridViewCellStyle();
            DataGridViewCellStyle style10 = new DataGridViewCellStyle();
            DataGridViewCellStyle style11 = new DataGridViewCellStyle();
            DataGridViewCellStyle style12 = new DataGridViewCellStyle();
            this.txtPs_Co_Nt = new TextNumeric();
            this.txtPs_No_Nt = new TextNumeric();
            this.txtPs_Co = new TextNumeric();
            this.txtPs_No = new TextNumeric();
            this.txtUN_TTien = new TextNumeric();
            this.txtIL_TTien = new TextNumeric();
            this.grdDetail = new GridDetail();
            this.Column1 = new OptionColumn();
            this.Column2 = new SearchColumn();
            this.Column3 = new OptionColumn();
            this.Column4 = new NumericColumn();
            this.Column5 = new NumericColumn();
            this.Column6 = new NumericColumn();
            this.Column7 = new SearchColumn();
            this.Column8 = new SearchColumn();
            this.Column9 = new SearchColumn();
            this.Column10 = new DateColumn();
            this.Column11 = new SearchColumn();
            this.Column12 = new SearchColumn();
            this.Column13 = new DataGridViewTextBoxColumn();
            this.Column14 = new DataGridViewTextBoxColumn();
            this.txtDesc_EN = new TextControl();
            this.txtDien_Giai = new TextControl();
            this.txtDia_Chi = new TextControl();
            this.txtOng_Ba = new TextControl();
            this.txtTen_Dt = new TextControl();
            this.txtTen_Hd = new TextControl();
            this.txtTen_Bp = new TextControl();
            this.lblPs_Co_Nt = new LabelControl();
            this.lblDesc_EN = new LabelControl();
            this.lblUN_TTien = new LabelControl();
            this.lblPs_No_Nt = new LabelControl();
            this.txtMa_Dt = new TextSearch();
            this.lblIL_TTien = new LabelControl();
            this.lblDien_Giai = new LabelControl();
            this.lblDia_Chi = new LabelControl();
            this.lblOng_Ba = new LabelControl();
            this.lblMa_Dt = new LabelControl();
            this.txtMa_Hd = new TextSearch();
            this.lblMa_Hd = new LabelControl();
            this.txtMa_Bp = new TextSearch();
            this.lblMa_Bp = new LabelControl();
            this.txtTy_Gia = new TextNumeric();
            this.lblMa_Tte = new LabelControl();
            this.txtMa_Tte = new TextOption();
            this.lblCt_Di_Kem = new LabelControl();
            this.txtCt_Di_Kem = new TextControl();
            this.lblCt_Di_Kem0 = new LabelControl();
            ((ISupportInitialize) this.grdDetail).BeginInit();
            base.SuspendLayout();
            base.txtMa_Loai1.TabIndex = 0x13;
            base.txtMa_Loai2.TabIndex = 20;
            base.txtMa_Loai3.TabIndex = 0x15;
            this.txtPs_Co_Nt.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.txtPs_Co_Nt.BackColor = Color.White;
            this.txtPs_Co_Nt.Enabled = false;
            this.txtPs_Co_Nt.Font = new Font("Arial", 8.25f);
            this.txtPs_Co_Nt.ForeColor = Color.Black;
            this.txtPs_Co_Nt.Location = new Point(0x259, 0x1d2);
            this.txtPs_Co_Nt.Name = "txtPs_Co_Nt";
            int[] bits = new int[4];
            this.txtPs_Co_Nt.NumericValue = new decimal(bits);
            this.txtPs_Co_Nt.OldValue = null;
            this.txtPs_Co_Nt.Size = new Size(90, 20);
            this.txtPs_Co_Nt.TabIndex = 0x53;
            this.txtPs_Co_Nt.TextAlign = HorizontalAlignment.Right;
            this.txtPs_Co_Nt.UserTextNumericFormat = AppInstance.TextNumericFormat.ForeignAmount;
//            this.txtPs_Co_Nt.Value = null;//manager.GetObject("txtPs_Co_Nt.Value");
            this.txtPs_No_Nt.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.txtPs_No_Nt.BackColor = Color.White;
            this.txtPs_No_Nt.Enabled = false;
            this.txtPs_No_Nt.Font = new Font("Arial", 8.25f);
            this.txtPs_No_Nt.ForeColor = Color.Black;
            this.txtPs_No_Nt.Location = new Point(0x259, 0x1bd);
            this.txtPs_No_Nt.Name = "txtPs_No_Nt";
            int[] numArray2 = new int[4];
            this.txtPs_No_Nt.NumericValue = new decimal(numArray2);
            this.txtPs_No_Nt.OldValue = null;
            this.txtPs_No_Nt.Size = new Size(90, 20);
            this.txtPs_No_Nt.TabIndex = 0x55;
            this.txtPs_No_Nt.TextAlign = HorizontalAlignment.Right;
            this.txtPs_No_Nt.UserTextNumericFormat = AppInstance.TextNumericFormat.ForeignAmount;
//            this.txtPs_No_Nt.Value = null;//manager.GetObject("txtPs_No_Nt.Value");
            this.txtPs_Co.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.txtPs_Co.BackColor = Color.White;
            this.txtPs_Co.Enabled = false;
            this.txtPs_Co.Font = new Font("Arial", 8.25f);
            this.txtPs_Co.ForeColor = Color.Black;
            this.txtPs_Co.Location = new Point(0x2b4, 0x1d2);
            this.txtPs_Co.Name = "txtPs_Co";
            int[] numArray3 = new int[4];
            this.txtPs_Co.NumericValue = new decimal(numArray3);
            this.txtPs_Co.OldValue = null;
            this.txtPs_Co.Size = new Size(90, 20);
            this.txtPs_Co.TabIndex = 0x54;
            this.txtPs_Co.TextAlign = HorizontalAlignment.Right;
            this.txtPs_Co.UserTextNumericFormat = AppInstance.TextNumericFormat.LocalAmount;
//            this.txtPs_Co.Value = null;//manager.GetObject("txtPs_Co.Value");
            this.txtPs_No.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.txtPs_No.BackColor = Color.White;
            this.txtPs_No.Enabled = false;
            this.txtPs_No.Font = new Font("Arial", 8.25f);
            this.txtPs_No.ForeColor = Color.Black;
            this.txtPs_No.Location = new Point(0x2b4, 0x1bd);
            this.txtPs_No.Name = "txtPs_No";
            int[] numArray4 = new int[4];
            this.txtPs_No.NumericValue = new decimal(numArray4);
            this.txtPs_No.OldValue = null;
            this.txtPs_No.Size = new Size(90, 20);
            this.txtPs_No.TabIndex = 0x56;
            this.txtPs_No.TextAlign = HorizontalAlignment.Right;
            this.txtPs_No.UserTextNumericFormat = AppInstance.TextNumericFormat.LocalAmount;
//            this.txtPs_No.Value = null;//manager.GetObject("txtPs_No.Value");
            this.txtUN_TTien.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
            this.txtUN_TTien.BackColor = Color.White;
            this.txtUN_TTien.DisabledBackColor = Color.Empty;
            this.txtUN_TTien.Font = new Font("Arial", 8.25f);
            this.txtUN_TTien.ForeColor = Color.Black;
            this.txtUN_TTien.Location = new Point(0x9d, 0x1d2);
            this.txtUN_TTien.Name = "txtUN_TTien";
            int[] numArray5 = new int[4];
            this.txtUN_TTien.NumericValue = new decimal(numArray5);
            this.txtUN_TTien.OldValue = null;
            this.txtUN_TTien.Size = new Size(90, 20);
            this.txtUN_TTien.TabIndex = 0x11;
            this.txtUN_TTien.TextAlign = HorizontalAlignment.Right;
            this.txtUN_TTien.UserTextNumericFormat = AppInstance.TextNumericFormat.LocalAmount;
//            this.txtUN_TTien.Value = null;//manager.GetObject("txtUN_TTien.Value");
            this.txtIL_TTien.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
            this.txtIL_TTien.BackColor = Color.White;
            this.txtIL_TTien.DisabledBackColor = Color.Empty;
            this.txtIL_TTien.Font = new Font("Arial", 8.25f);
            this.txtIL_TTien.ForeColor = Color.Black;
            this.txtIL_TTien.Location = new Point(0x9d, 0x1bd);
            this.txtIL_TTien.Name = "txtIL_TTien";
            int[] numArray6 = new int[4];
            this.txtIL_TTien.NumericValue = new decimal(numArray6);
            this.txtIL_TTien.OldValue = null;
            this.txtIL_TTien.Size = new Size(90, 20);
            this.txtIL_TTien.TabIndex = 0x10;
            this.txtIL_TTien.TextAlign = HorizontalAlignment.Right;
            this.txtIL_TTien.UserTextNumericFormat = AppInstance.TextNumericFormat.LocalAmount;
//            this.txtIL_TTien.Value = null;//manager.GetObject("txtIL_TTien.Value");
            this.grdDetail.AllowUserToAddRows = false;
            this.grdDetail.AllowUserToDeleteRows = false;
            this.grdDetail.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top;
            this.grdDetail.CheckAutoSize = true;
            this.grdDetail.CheckColor = false;
            this.grdDetail.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.grdDetail.Columns.AddRange(new DataGridViewColumn[] { this.Column1, this.Column2, this.Column3, this.Column4, this.Column5, this.Column6, this.Column7, this.Column8, this.Column9, this.Column10, this.Column11, this.Column12, this.Column13, this.Column14 });
            this.grdDetail.FirstColumnIndex = 1;
            this.grdDetail.Font = new Font("Arial", 8.25f);
            this.grdDetail.Location = new Point(0, 0xb8);
            this.grdDetail.Name = "grdDetail";
            this.grdDetail.Size = new Size(0x31a, 0xff);
            this.grdDetail.TabIndex = 15;
            this.grdDetail.CellRightLeaved += new EventHandler(this.grdDetail_CellRightLeaved);
            this.grdDetail.CellBottomLeftLeaved += new EventHandler(this.grdDetail_CellBottomLeftLeaved);
            this.Column1.DataPropertyName = "No_Co";
            style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            this.Column1.DefaultCellStyle = style;
            this.Column1.DisabledForeColor = Color.Blue;
            this.Column1.HeaderText = "Ps";
            this.Column1.InputMask = "N,C";
            this.Column1.Name = "Column1";
            this.Column1.Resizable = DataGridViewTriState.False;
            this.Column1.SortMode = DataGridViewColumnSortMode.Automatic;
            this.Column1.UserTextLength = AppInstance.TextControlLength.None;
            this.Column1.Width = 20;
            this.Column2.DataPropertyName = "Tk";
            style2.Alignment = DataGridViewContentAlignment.MiddleLeft;
            this.Column2.DefaultCellStyle = style2;
            this.Column2.DestinationFields = "Ten_Tk, Tk_NT, Tk_BP, Tk_HD, Tk_DT, Tk_GT, Tk_KM, Tk_VAT";
            this.Column2.DisabledForeColor = Color.Blue;
            this.Column2.EmptyIsValid = true;
            this.Column2.FirstFilter = "Loai_Tk = 'C'";
            this.Column2.HeaderText = "T\x00e0i khoản";
            this.Column2.Name = "Column2";
            this.Column2.SortMode = DataGridViewColumnSortMode.Automatic;
            this.Column2.SourceFields = "Ten_Tk, Tk_NT, Tk_BP, Tk_HD, Tk_DT, Tk_GT, Tk_KM, Tk_VAT";
            this.Column2.TableName = "DMTK";
            this.Column2.UserTrimMode = AppInstance.TextControlTrimMode.All;
            this.Column2.Width = 40;
            this.Column3.DataPropertyName = "Ma_Tte";
            style3.Alignment = DataGridViewContentAlignment.MiddleLeft;
            this.Column3.DefaultCellStyle = style3;
            this.Column3.DisabledForeColor = Color.Blue;
            this.Column3.HeaderText = "Ttệ";
            this.Column3.Name = "Column3";
            this.Column3.Resizable = DataGridViewTriState.False;
            this.Column3.SortMode = DataGridViewColumnSortMode.Automatic;
            this.Column3.UserTextLength = AppInstance.TextControlLength.None;
            this.Column3.Width = 30;
            this.Column4.DataPropertyName = "Tien_Nt";
            style4.Alignment = DataGridViewContentAlignment.MiddleRight;
            this.Column4.DefaultCellStyle = style4;
            this.Column4.HeaderText = "Nguy\x00ean tệ";
            this.Column4.Name = "Column4";
            this.Column4.SortMode = DataGridViewColumnSortMode.Automatic;
            this.Column4.UserTextNumericFormat = AppInstance.TextNumericFormat.ForeignAmount;
            this.Column4.Width = 70;
            this.Column4.ZeroIsShown = true;
            this.Column4.ZeroIsValid = true;
            this.Column5.AllowNegative = false;
            this.Column5.DataPropertyName = "Ty_Gia";
            style5.Alignment = DataGridViewContentAlignment.MiddleRight;
            this.Column5.DefaultCellStyle = style5;
            this.Column5.HeaderText = "Tỷ giá";
            this.Column5.Name = "Column5";
            this.Column5.SortMode = DataGridViewColumnSortMode.Automatic;
            this.Column5.UserTextNumericFormat = AppInstance.TextNumericFormat.ExchangeRate;
            this.Column5.Width = 50;
            this.Column5.ZeroIsShown = true;
            this.Column6.DataPropertyName = "Tien";
            style6.Alignment = DataGridViewContentAlignment.MiddleRight;
            this.Column6.DefaultCellStyle = style6;
            this.Column6.HeaderText = "Thành tiền";
            this.Column6.Name = "Column6";
            this.Column6.SortMode = DataGridViewColumnSortMode.Automatic;
            this.Column6.UserTextNumericFormat = AppInstance.TextNumericFormat.LocalAmount;
            this.Column6.Width = 70;
            this.Column6.ZeroIsShown = true;
            this.Column6.ZeroIsValid = true;
            this.Column7.DataPropertyName = "Ma_Bp";
            style7.Alignment = DataGridViewContentAlignment.MiddleLeft;
            this.Column7.DefaultCellStyle = style7;
            this.Column7.DestinationFields = "Ten_Bp";
            this.Column7.DisabledForeColor = Color.Blue;
            this.Column7.EmptyIsValid = true;
            this.Column7.HeaderText = "Bộ phận";
            this.Column7.Name = "Column7";
            this.Column7.SortMode = DataGridViewColumnSortMode.Automatic;
            this.Column7.SourceFields = "Ten_Bp";
            this.Column7.TableName = "DMBP";
            this.Column7.UserTrimMode = AppInstance.TextControlTrimMode.All;
            this.Column7.Width = 40;
            this.Column8.DataPropertyName = "Ma_Hd";
            style8.Alignment = DataGridViewContentAlignment.MiddleLeft;
            this.Column8.DefaultCellStyle = style8;
            this.Column8.DestinationFields = "Ten_Hd";
            this.Column8.DisabledForeColor = Color.Blue;
            this.Column8.EmptyIsValid = true;
            this.Column8.HeaderText = "Hợp đồng";
            this.Column8.Name = "Column8";
            this.Column8.SortMode = DataGridViewColumnSortMode.Automatic;
            this.Column8.SourceFields = "Ten_Hd";
            this.Column8.TableName = "DMHD";
            this.Column8.UserTrimMode = AppInstance.TextControlTrimMode.All;
            this.Column8.Width = 40;
            this.Column9.DataPropertyName = "Ma_Dt";
            style9.Alignment = DataGridViewContentAlignment.MiddleLeft;
            this.Column9.DefaultCellStyle = style9;
            this.Column9.DestinationFields = "Ten_Dt";
            this.Column9.DisabledForeColor = Color.Blue;
            this.Column9.FirstFilter = "Is_Stop = '1'";
            this.Column9.HeaderText = "Đối tượng";
            this.Column9.Name = "Column9";
            this.Column9.SortMode = DataGridViewColumnSortMode.Automatic;
            this.Column9.SourceFields = "Ten_Dt";
            this.Column9.TableName = "DMDT";
            this.Column9.UserTrimMode = AppInstance.TextControlTrimMode.All;
            this.Column9.Width = 40;
            this.Column10.DataPropertyName = "Han_Tt";
            style10.Alignment = DataGridViewContentAlignment.MiddleLeft;
            this.Column10.DefaultCellStyle = style10;
            this.Column10.HeaderText = "Hạn T.toán";
            this.Column10.Name = "Column10";
            this.Column10.Resizable = DataGridViewTriState.False;
            this.Column10.Width = 0x3e;
            this.Column11.DataPropertyName = "Ma_Km";
            style11.Alignment = DataGridViewContentAlignment.MiddleLeft;
            this.Column11.DefaultCellStyle = style11;
            this.Column11.DestinationFields = "Ten_Km";
            this.Column11.DisabledForeColor = Color.Blue;
            this.Column11.EmptyIsValid = true;
            this.Column11.HeaderText = "Khoản mục";
            this.Column11.Name = "Column11";
            this.Column11.SortMode = DataGridViewColumnSortMode.Automatic;
            this.Column11.SourceFields = "Ten_Km";
            this.Column11.TableName = "DMKM";
            this.Column11.UserTrimMode = AppInstance.TextControlTrimMode.All;
            this.Column11.Width = 40;
            this.Column12.DataPropertyName = "Ma_Sp";
            style12.Alignment = DataGridViewContentAlignment.MiddleLeft;
            this.Column12.DefaultCellStyle = style12;
            this.Column12.DestinationFields = "Ten_Sp";
            this.Column12.DisabledForeColor = Color.Blue;
            this.Column12.EmptyIsValid = true;
            this.Column12.HeaderText = "Sản phẩm";
            this.Column12.Name = "Column12";
            this.Column12.SortMode = DataGridViewColumnSortMode.Automatic;
            this.Column12.SourceFields = "Ten_Sp";
            this.Column12.TableName = "DMSP";
            this.Column12.UserTrimMode = AppInstance.TextControlTrimMode.All;
            this.Column12.Width = 40;
            this.Column13.DataPropertyName = "Dien_Giai";
            this.Column13.FillWeight = 90f;
            this.Column13.HeaderText = "Diễn giải (VN)";
            this.Column13.Name = "Column13";
            this.Column13.SortMode = DataGridViewColumnSortMode.NotSortable;
            this.Column13.Width = 0x69;
            this.Column14.DataPropertyName = "Desc_EN";
            this.Column14.FillWeight = 90f;
            this.Column14.HeaderText = "Diễn giải (EN)";
            this.Column14.Name = "Column14";
            this.Column14.SortMode = DataGridViewColumnSortMode.NotSortable;
            this.Column14.Width = 0x68;
            this.txtDesc_EN.Anchor = AnchorStyles.Right | AnchorStyles.Top;
            this.txtDesc_EN.CheckTextSearched = false;
            this.txtDesc_EN.DisabledForeColor = Color.Blue;
            this.txtDesc_EN.Font = new Font("Arial", 8.25f);
            this.txtDesc_EN.Location = new Point(0x1e7, 0x9e);
            this.txtDesc_EN.MaxLength = 0xfe;
            this.txtDesc_EN.Name = "txtDesc_EN";
            this.txtDesc_EN.OldValue = null;
            this.txtDesc_EN.Size = new Size(0x127, 20);
            this.txtDesc_EN.TabIndex = 14;
            this.txtDesc_EN.UserTextLength = AppInstance.TextControlLength.InvoiceDescription;
//            this.txtDesc_EN.Value = null;//manager.GetObject("txtDesc_EN.Value");
            this.txtDesc_EN.Validated += new EventHandler(this.txtDesc_EN_Validated);
            this.txtDien_Giai.CheckTextSearched = false;
            this.txtDien_Giai.DisabledForeColor = Color.Blue;
            this.txtDien_Giai.Font = new Font("Arial", 8.25f);
            this.txtDien_Giai.Location = new Point(0x63, 0x9e);
            this.txtDien_Giai.MaxLength = 0xfe;
            this.txtDien_Giai.Name = "txtDien_Giai";
            this.txtDien_Giai.OldValue = null;
            this.txtDien_Giai.Size = new Size(0x128, 20);
            this.txtDien_Giai.TabIndex = 13;
            this.txtDien_Giai.UserTextLength = AppInstance.TextControlLength.InvoiceDescription;
//            this.txtDien_Giai.Value = null;//manager.GetObject("txtDien_Giai.Value");
            this.txtDien_Giai.Validated += new EventHandler(this.txtDien_Giai_Validated);
            this.txtDia_Chi.Anchor = AnchorStyles.Right | AnchorStyles.Top;
            this.txtDia_Chi.CheckTextSearched = false;
            this.txtDia_Chi.DisabledForeColor = Color.Blue;
            this.txtDia_Chi.Font = new Font("Arial", 8.25f);
            this.txtDia_Chi.Location = new Point(0x1e7, 0x89);
            this.txtDia_Chi.MaxLength = 0x80;
            this.txtDia_Chi.Name = "txtDia_Chi";
            this.txtDia_Chi.OldValue = null;
            this.txtDia_Chi.Size = new Size(0x127, 20);
            this.txtDia_Chi.TabIndex = 12;
            this.txtDia_Chi.UserTextLength = AppInstance.TextControlLength.ItemDescription;
//            this.txtDia_Chi.Value = null;//manager.GetObject("txtDia_Chi.Value");
            this.txtOng_Ba.CheckTextSearched = false;
            this.txtOng_Ba.DisabledForeColor = Color.Blue;
            this.txtOng_Ba.Font = new Font("Arial", 8.25f);
            this.txtOng_Ba.Location = new Point(0x63, 0x89);
            this.txtOng_Ba.MaxLength = 0x80;
            this.txtOng_Ba.Name = "txtOng_Ba";
            this.txtOng_Ba.OldValue = null;
            this.txtOng_Ba.Size = new Size(0x128, 20);
            this.txtOng_Ba.TabIndex = 11;
            this.txtOng_Ba.UserTextLength = AppInstance.TextControlLength.ItemDescription;
//            this.txtOng_Ba.Value = null;//manager.GetObject("txtOng_Ba.Value");
            this.txtTen_Dt.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtTen_Dt.BackColor = SystemColors.Control;
            this.txtTen_Dt.BorderStyle = BorderStyle.None;
            this.txtTen_Dt.CheckTextSearched = false;
            this.txtTen_Dt.DisabledForeColor = Color.Blue;
            this.txtTen_Dt.Enabled = false;
            this.txtTen_Dt.Font = new Font("Arial", 8.25f);
            this.txtTen_Dt.ForeColor = Color.Blue;
            this.txtTen_Dt.Location = new Point(0xdf, 0x77);
            this.txtTen_Dt.Name = "txtTen_Dt";
            this.txtTen_Dt.OldValue = null;
            this.txtTen_Dt.Size = new Size(0x22f, 13);
            this.txtTen_Dt.TabIndex = 0x48;
//            this.txtTen_Dt.Value = null;//manager.GetObject("txtTen_Dt.Value");
            this.txtTen_Hd.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtTen_Hd.BackColor = SystemColors.Control;
            this.txtTen_Hd.BorderStyle = BorderStyle.None;
            this.txtTen_Hd.CheckTextSearched = false;
            this.txtTen_Hd.DisabledForeColor = Color.Blue;
            this.txtTen_Hd.Enabled = false;
            this.txtTen_Hd.Font = new Font("Arial", 8.25f);
            this.txtTen_Hd.ForeColor = Color.Blue;
            this.txtTen_Hd.Location = new Point(0xdf, 0x62);
            this.txtTen_Hd.Name = "txtTen_Hd";
            this.txtTen_Hd.OldValue = null;
            this.txtTen_Hd.Size = new Size(0x22f, 13);
            this.txtTen_Hd.TabIndex = 0x49;
//            this.txtTen_Hd.Value = null;//manager.GetObject("txtTen_Hd.Value");
            this.txtTen_Bp.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtTen_Bp.BackColor = SystemColors.Control;
            this.txtTen_Bp.BorderStyle = BorderStyle.None;
            this.txtTen_Bp.CheckTextSearched = false;
            this.txtTen_Bp.DisabledForeColor = Color.Blue;
            this.txtTen_Bp.Enabled = false;
            this.txtTen_Bp.Font = new Font("Arial", 8.25f);
            this.txtTen_Bp.ForeColor = Color.Blue;
            this.txtTen_Bp.Location = new Point(0xdf, 0x4d);
            this.txtTen_Bp.Name = "txtTen_Bp";
            this.txtTen_Bp.OldValue = null;
            this.txtTen_Bp.Size = new Size(0x22f, 13);
            this.txtTen_Bp.TabIndex = 0x4a;
//            this.txtTen_Bp.Value = null;//manager.GetObject("txtTen_Bp.Value");
            this.lblPs_Co_Nt.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.lblPs_Co_Nt.AutoSize = true;
            this.lblPs_Co_Nt.Font = new Font("Arial", 8.25f);
            this.lblPs_Co_Nt.Location = new Point(0x210, 0x1d5);
            this.lblPs_Co_Nt.Name = "lblPs_Co_Nt";
            this.lblPs_Co_Nt.Size = new Size(0x42, 14);
            this.lblPs_Co_Nt.TabIndex = 0x40;
            this.lblPs_Co_Nt.Text = "Ph\x00e1t sinh có";
            this.lblDesc_EN.Anchor = AnchorStyles.Right | AnchorStyles.Top;
            this.lblDesc_EN.AutoSize = true;
            this.lblDesc_EN.Font = new Font("Arial", 8.25f);
            this.lblDesc_EN.Location = new Point(410, 0xa1);
            this.lblDesc_EN.Name = "lblDesc_EN";
            this.lblDesc_EN.Size = new Size(0x47, 14);
            this.lblDesc_EN.TabIndex = 0x41;
            this.lblDesc_EN.Text = "Diễn giải (EN)";
            this.lblUN_TTien.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
            this.lblUN_TTien.AutoSize = true;
            this.lblUN_TTien.Font = new Font("Arial", 8.25f);
            this.lblUN_TTien.Location = new Point(12, 0x1d5);
            this.lblUN_TTien.Name = "lblUN_TTien";
            this.lblUN_TTien.Size = new Size(0x87, 14);
            this.lblUN_TTien.TabIndex = 0x3f;
            this.lblUN_TTien.Text = "Doanh thu chưa hạch toán";
            this.lblPs_No_Nt.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.lblPs_No_Nt.AutoSize = true;
            this.lblPs_No_Nt.Font = new Font("Arial", 8.25f);
            this.lblPs_No_Nt.Location = new Point(0x210, 0x1c0);
            this.lblPs_No_Nt.Name = "lblPs_No_Nt";
            this.lblPs_No_Nt.Size = new Size(0x43, 14);
            this.lblPs_No_Nt.TabIndex = 0x3d;
            this.lblPs_No_Nt.Text = "Ph\x00e1t sinh nợ";
            this.txtMa_Dt.CharacterCasing = CharacterCasing.Upper;
            this.txtMa_Dt.CheckTextSearched = false;
            this.txtMa_Dt.DisabledForeColor = Color.Empty;
            this.txtMa_Dt.EmptyIsValid = true;
            this.txtMa_Dt.FieldDisplay = "Ten_Dt";
            this.txtMa_Dt.FirstFilter = "Is_Stop = '1'";
            this.txtMa_Dt.Font = new Font("Arial", 8.25f);
            this.txtMa_Dt.Location = new Point(0x63, 0x74);
            this.txtMa_Dt.MaxLength = 0x20;
            this.txtMa_Dt.Name = "txtMa_Dt";
            this.txtMa_Dt.OldValue = null;
            this.txtMa_Dt.Size = new Size(0x76, 20);
            this.txtMa_Dt.TabIndex = 10;
            this.txtMa_Dt.TableName = "DMDT";
            this.txtMa_Dt.TextDisplay = this.txtTen_Dt;
            this.txtMa_Dt.UserTextLength = AppInstance.TextControlLength.ItemCode;
            this.txtMa_Dt.UserTrimMode = AppInstance.TextControlTrimMode.All;
//            this.txtMa_Dt.Value = null;//manager.GetObject("txtMa_Dt.Value");
            this.txtMa_Dt.Validated += new EventHandler(this.txtMa_Dt_Validated);
            this.lblIL_TTien.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
            this.lblIL_TTien.AutoSize = true;
            this.lblIL_TTien.Font = new Font("Arial", 8.25f);
            this.lblIL_TTien.Location = new Point(12, 0x1c0);
            this.lblIL_TTien.Name = "lblIL_TTien";
            this.lblIL_TTien.Size = new Size(0x68, 14);
            this.lblIL_TTien.TabIndex = 0x3e;
            this.lblIL_TTien.Text = "Chi phí không hợp lệ";
            this.lblDien_Giai.AutoSize = true;
            this.lblDien_Giai.Font = new Font("Arial", 8.25f);
            this.lblDien_Giai.Location = new Point(12, 0xa1);
            this.lblDien_Giai.Name = "lblDien_Giai";
            this.lblDien_Giai.Size = new Size(0x49, 14);
            this.lblDien_Giai.TabIndex = 0x42;
            this.lblDien_Giai.Text = "Diễn giải (VN)";
            this.lblDia_Chi.Anchor = AnchorStyles.Right | AnchorStyles.Top;
            this.lblDia_Chi.AutoSize = true;
            this.lblDia_Chi.Font = new Font("Arial", 8.25f);
            this.lblDia_Chi.Location = new Point(0x1b9, 140);
            this.lblDia_Chi.Name = "lblDia_Chi";
            this.lblDia_Chi.Size = new Size(40, 14);
            this.lblDia_Chi.TabIndex = 70;
            this.lblDia_Chi.Text = "Địa chỉ";
            this.lblOng_Ba.AutoSize = true;
            this.lblOng_Ba.Font = new Font("Arial", 8.25f);
            this.lblOng_Ba.Location = new Point(12, 140);
            this.lblOng_Ba.Name = "lblOng_Ba";
            this.lblOng_Ba.Size = new Size(0x2a, 14);
            this.lblOng_Ba.TabIndex = 0x47;
            this.lblOng_Ba.Text = "\x00d4ng b\x00e0";
            this.lblMa_Dt.AutoSize = true;
            this.lblMa_Dt.Font = new Font("Arial", 8.25f);
            this.lblMa_Dt.Location = new Point(12, 0x77);
            this.lblMa_Dt.Name = "lblMa_Dt";
            this.lblMa_Dt.Size = new Size(0x37, 14);
            this.lblMa_Dt.TabIndex = 0x45;
            this.lblMa_Dt.Text = "Đối tượng";
            this.txtMa_Hd.CharacterCasing = CharacterCasing.Upper;
            this.txtMa_Hd.CheckTextSearched = false;
            this.txtMa_Hd.DisabledForeColor = Color.Empty;
            this.txtMa_Hd.EmptyIsValid = true;
            this.txtMa_Hd.FieldDisplay = "Ten_Hd";
            this.txtMa_Hd.Font = new Font("Arial", 8.25f);
            this.txtMa_Hd.FoundIsValid = true;
            this.txtMa_Hd.Location = new Point(0x63, 0x5f);
            this.txtMa_Hd.MaxLength = 0x20;
            this.txtMa_Hd.Name = "txtMa_Hd";
            this.txtMa_Hd.OldValue = null;
            this.txtMa_Hd.Size = new Size(0x76, 20);
            this.txtMa_Hd.TabIndex = 9;
            this.txtMa_Hd.TableName = "DMHD";
            this.txtMa_Hd.TextDisplay = this.txtTen_Hd;
            this.txtMa_Hd.UserTextLength = AppInstance.TextControlLength.ItemCode;
            this.txtMa_Hd.UserTrimMode = AppInstance.TextControlTrimMode.All;
//            this.txtMa_Hd.Value = null;//manager.GetObject("txtMa_Hd.Value");
            this.txtMa_Hd.Validated += new EventHandler(this.txtMa_Hd_Validated);
            this.lblMa_Hd.AutoSize = true;
            this.lblMa_Hd.Font = new Font("Arial", 8.25f);
            this.lblMa_Hd.Location = new Point(12, 0x62);
            this.lblMa_Hd.Name = "lblMa_Hd";
            this.lblMa_Hd.Size = new Size(0x36, 14);
            this.lblMa_Hd.TabIndex = 0x43;
            this.lblMa_Hd.Text = "Hợp đồng";
            this.txtMa_Bp.CharacterCasing = CharacterCasing.Upper;
            this.txtMa_Bp.CheckTextSearched = false;
            this.txtMa_Bp.DisabledForeColor = Color.Empty;
            this.txtMa_Bp.EmptyIsValid = true;
            this.txtMa_Bp.FieldDisplay = "Ten_Bp";
            this.txtMa_Bp.Font = new Font("Arial", 8.25f);
            this.txtMa_Bp.FoundIsValid = true;
            this.txtMa_Bp.Location = new Point(0x63, 0x4a);
            this.txtMa_Bp.MaxLength = 0x20;
            this.txtMa_Bp.Name = "txtMa_Bp";
            this.txtMa_Bp.OldValue = null;
            this.txtMa_Bp.Size = new Size(0x76, 20);
            this.txtMa_Bp.TabIndex = 8;
            this.txtMa_Bp.TableName = "DMBP";
            this.txtMa_Bp.TextDisplay = this.txtTen_Bp;
            this.txtMa_Bp.UserTextLength = AppInstance.TextControlLength.ItemCode;
            this.txtMa_Bp.UserTrimMode = AppInstance.TextControlTrimMode.All;
//            this.txtMa_Bp.Value = null;//manager.GetObject("txtMa_Bp.Value");
            this.txtMa_Bp.Validated += new EventHandler(this.txtMa_Bp_Validated);
            this.lblMa_Bp.AutoSize = true;
            this.lblMa_Bp.Font = new Font("Arial", 8.25f);
            this.lblMa_Bp.Location = new Point(12, 0x4d);
            this.lblMa_Bp.Name = "lblMa_Bp";
            this.lblMa_Bp.Size = new Size(0x2f, 14);
            this.lblMa_Bp.TabIndex = 0x44;
            this.lblMa_Bp.Text = "Bộ phận";
            this.txtTy_Gia.Anchor = AnchorStyles.Right | AnchorStyles.Top;
            this.txtTy_Gia.BackColor = Color.White;
            this.txtTy_Gia.DisabledBackColor = Color.Empty;
            this.txtTy_Gia.Font = new Font("Arial", 8.25f);
            this.txtTy_Gia.ForeColor = Color.Black;
            this.txtTy_Gia.Location = new Point(0x2d4, 0x35);
            this.txtTy_Gia.Name = "txtTy_Gia";
            int[] numArray7 = new int[4];
            this.txtTy_Gia.NumericValue = new decimal(numArray7);
            this.txtTy_Gia.OldValue = null;
            this.txtTy_Gia.Size = new Size(0x3a, 20);
            this.txtTy_Gia.TabIndex = 7;
            this.txtTy_Gia.TextAlign = HorizontalAlignment.Right;
            this.txtTy_Gia.UserTextNumericFormat = AppInstance.TextNumericFormat.ExchangeRate;
//            this.txtTy_Gia.Value = null;//manager.GetObject("txtTy_Gia.Value");
            this.txtTy_Gia.Validated += new EventHandler(this.txtTy_Gia_Validated);
            this.lblMa_Tte.Anchor = AnchorStyles.Right | AnchorStyles.Top;
            this.lblMa_Tte.AutoSize = true;
            this.lblMa_Tte.Font = new Font("Arial", 8.25f);
            this.lblMa_Tte.Location = new Point(0x28c, 0x38);
            this.lblMa_Tte.Name = "lblMa_Tte";
            this.lblMa_Tte.Size = new Size(0x27, 14);
            this.lblMa_Tte.TabIndex = 0x3d;
            this.lblMa_Tte.Text = "Tiền tệ";
            this.txtMa_Tte.Anchor = AnchorStyles.Right | AnchorStyles.Top;
            this.txtMa_Tte.CharacterCasing = CharacterCasing.Upper;
            this.txtMa_Tte.CheckTextSearched = false;
            this.txtMa_Tte.DisabledForeColor = Color.Blue;
            this.txtMa_Tte.Font = new Font("Arial", 8.25f);
            this.txtMa_Tte.InputMask = "USD,VND";
            this.txtMa_Tte.Location = new Point(0x2b9, 0x35);
            this.txtMa_Tte.Name = "txtMa_Tte";
            this.txtMa_Tte.OldValue = null;
            this.txtMa_Tte.Size = new Size(0x1c, 20);
            this.txtMa_Tte.TabIndex = 6;
            this.txtMa_Tte.Text = "USD";
            this.txtMa_Tte.Value = "USD";
            this.txtMa_Tte.Validated += new EventHandler(this.txtMa_Tte_Validated);
            this.lblCt_Di_Kem.Anchor = AnchorStyles.Bottom;
            this.lblCt_Di_Kem.AutoSize = true;
            this.lblCt_Di_Kem.Font = new Font("Arial", 8.25f);
            this.lblCt_Di_Kem.Location = new Point(0x12e, 0x1c9);
            this.lblCt_Di_Kem.Name = "lblCt_Di_Kem";
            this.lblCt_Di_Kem.Size = new Size(0x34, 14);
            this.lblCt_Di_Kem.TabIndex = 0x41;
            this.lblCt_Di_Kem.Text = "K\x00e8m theo";
            this.txtCt_Di_Kem.Anchor = AnchorStyles.Bottom;
            this.txtCt_Di_Kem.CheckTextSearched = false;
            this.txtCt_Di_Kem.DisabledForeColor = Color.Blue;
            this.txtCt_Di_Kem.Font = new Font("Arial", 8.25f);
            this.txtCt_Di_Kem.Location = new Point(360, 0x1c6);
            this.txtCt_Di_Kem.Name = "txtCt_Di_Kem";
            this.txtCt_Di_Kem.OldValue = null;
            this.txtCt_Di_Kem.Size = new Size(0x29, 20);
            this.txtCt_Di_Kem.TabIndex = 0x12;
//            this.txtCt_Di_Kem.Value = null;//manager.GetObject("txtCt_Di_Kem.Value");
            this.lblCt_Di_Kem0.Anchor = AnchorStyles.Bottom;
            this.lblCt_Di_Kem0.AutoSize = true;
            this.lblCt_Di_Kem0.Font = new Font("Arial", 8.25f);
            this.lblCt_Di_Kem0.Location = new Point(0x197, 0x1c9);
            this.lblCt_Di_Kem0.Name = "lblCt_Di_Kem0";
            this.lblCt_Di_Kem0.Size = new Size(0x4b, 14);
            this.lblCt_Di_Kem0.TabIndex = 0x41;
            this.lblCt_Di_Kem0.Text = "chứng từ gốc.";
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.ClientSize = new Size(0x31a, 0x214);
            base.Controls.Add(this.txtMa_Tte);
            base.Controls.Add(this.txtPs_Co_Nt);
            base.Controls.Add(this.txtPs_No_Nt);
            base.Controls.Add(this.txtPs_Co);
            base.Controls.Add(this.txtTy_Gia);
            base.Controls.Add(this.txtPs_No);
            base.Controls.Add(this.txtUN_TTien);
            base.Controls.Add(this.txtIL_TTien);
            base.Controls.Add(this.grdDetail);
            base.Controls.Add(this.txtCt_Di_Kem);
            base.Controls.Add(this.txtDesc_EN);
            base.Controls.Add(this.txtDien_Giai);
            base.Controls.Add(this.txtDia_Chi);
            base.Controls.Add(this.txtOng_Ba);
            base.Controls.Add(this.txtTen_Dt);
            base.Controls.Add(this.txtTen_Hd);
            base.Controls.Add(this.txtTen_Bp);
            base.Controls.Add(this.lblCt_Di_Kem0);
            base.Controls.Add(this.lblCt_Di_Kem);
            base.Controls.Add(this.lblPs_Co_Nt);
            base.Controls.Add(this.lblDesc_EN);
            base.Controls.Add(this.lblUN_TTien);
            base.Controls.Add(this.lblMa_Tte);
            base.Controls.Add(this.lblPs_No_Nt);
            base.Controls.Add(this.txtMa_Dt);
            base.Controls.Add(this.lblIL_TTien);
            base.Controls.Add(this.lblDien_Giai);
            base.Controls.Add(this.lblDia_Chi);
            base.Controls.Add(this.lblOng_Ba);
            base.Controls.Add(this.lblMa_Dt);
            base.Controls.Add(this.txtMa_Hd);
            base.Controls.Add(this.lblMa_Hd);
            base.Controls.Add(this.txtMa_Bp);
            base.Controls.Add(this.lblMa_Bp);
            base.Name = "FormCTKTEditor";
            base.Controls.SetChildIndex(base.txtSo_Ct, 0);
            base.Controls.SetChildIndex(base.txtNgay_Ps, 0);
            base.Controls.SetChildIndex(base.txtNgay_Ct, 0);
            base.Controls.SetChildIndex(base.lblPhan_Loai, 0);
            base.Controls.SetChildIndex(base.txtMa_Loai1, 0);
            base.Controls.SetChildIndex(base.txtMa_Loai2, 0);
            base.Controls.SetChildIndex(base.txtMa_Loai3, 0);
            base.Controls.SetChildIndex(this.lblMa_Bp, 0);
            base.Controls.SetChildIndex(this.txtMa_Bp, 0);
            base.Controls.SetChildIndex(this.lblMa_Hd, 0);
            base.Controls.SetChildIndex(this.txtMa_Hd, 0);
            base.Controls.SetChildIndex(this.lblMa_Dt, 0);
            base.Controls.SetChildIndex(this.lblOng_Ba, 0);
            base.Controls.SetChildIndex(this.lblDia_Chi, 0);
            base.Controls.SetChildIndex(this.lblDien_Giai, 0);
            base.Controls.SetChildIndex(this.lblIL_TTien, 0);
            base.Controls.SetChildIndex(this.txtMa_Dt, 0);
            base.Controls.SetChildIndex(this.lblPs_No_Nt, 0);
            base.Controls.SetChildIndex(this.lblMa_Tte, 0);
            base.Controls.SetChildIndex(this.lblUN_TTien, 0);
            base.Controls.SetChildIndex(this.lblDesc_EN, 0);
            base.Controls.SetChildIndex(this.lblPs_Co_Nt, 0);
            base.Controls.SetChildIndex(this.lblCt_Di_Kem, 0);
            base.Controls.SetChildIndex(this.lblCt_Di_Kem0, 0);
            base.Controls.SetChildIndex(this.txtTen_Bp, 0);
            base.Controls.SetChildIndex(this.txtTen_Hd, 0);
            base.Controls.SetChildIndex(this.txtTen_Dt, 0);
            base.Controls.SetChildIndex(this.txtOng_Ba, 0);
            base.Controls.SetChildIndex(this.txtDia_Chi, 0);
            base.Controls.SetChildIndex(this.txtDien_Giai, 0);
            base.Controls.SetChildIndex(this.txtDesc_EN, 0);
            base.Controls.SetChildIndex(this.txtCt_Di_Kem, 0);
            base.Controls.SetChildIndex(this.grdDetail, 0);
            base.Controls.SetChildIndex(this.txtIL_TTien, 0);
            base.Controls.SetChildIndex(this.txtUN_TTien, 0);
            base.Controls.SetChildIndex(this.txtPs_No, 0);
            base.Controls.SetChildIndex(this.txtTy_Gia, 0);
            base.Controls.SetChildIndex(this.txtPs_Co, 0);
            base.Controls.SetChildIndex(this.txtPs_No_Nt, 0);
            base.Controls.SetChildIndex(this.txtPs_Co_Nt, 0);
            base.Controls.SetChildIndex(this.txtMa_Tte, 0);
            ((ISupportInitialize) this.grdDetail).EndInit();
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        internal override void OnAdd()
        {
            object obj2 = base.LocalMasterRow["So_Ct"];
            object obj3 = SDBNull.Value;
            base.LocalMasterRow = base.MakeMasterRow();
            base.LocalMasterRow["Nh_Ct"] = base.SSInvoiceParameters.InvoiceType;
            base.LocalMasterRow["So_Ct"] = this.oMethod.Cong_So_Ct(AppInstance.Subsidiary, base.InvoiceCode, obj3, base.LocalMasterRow["Ngay_Ct"], obj2);
            base.LocalMasterRow["Ma_Tte"] = AppInstance.DefaultCurrency;
            base.LocalMasterRow["Ty_Gia"] = 1;
            base.LocalMasterRow["Ty_Gia_Ht"] = 1;
            base.LocalMasterRow["TTien_NtN"] = 0;
            base.LocalMasterRow["TTien_NtC"] = 0;
            base.LocalMasterRow["TTien"] = 0;
            base.LocalMasterRow["TTien_VAT0"] = 0;
            base.LocalMasterRow["TTien_VAT1"] = 0;
            base.MakeDetailTable();
            base.LocalDetailTable.Rows[0]["Stt_Nv"] = 1;
            base.LocalDetailTable.Rows[0]["No_Co"] = "N";
            base.LocalDetailTable.Rows[0]["Ma_Tte"] = AppInstance.DefaultCurrency;
            base.LocalDetailTable.Rows[0]["Ty_Gia"] = 1;
            base.LocalDetailTable.Rows[0]["Ty_Gia_Ht"] = 1;
            base.LocalDetailTable.Rows[0]["Tien_Nt"] = 0;
            base.LocalDetailTable.Rows[0]["Tien"] = 0;
            base.LocalDetailTable.Rows[0]["Dien_Giai"] = base.LocalMasterRow["Dien_Giai"];
            base.LocalDetailTable.Rows[0]["Desc_EN"] = base.LocalMasterRow["Desc_EN"];
            base.LocalDetailTable.Rows[0]["Ma_Dt"] = base.LocalMasterRow["Ma_Dt"];
            if (base.SSInvoiceParameters.AllowDepartmentControl != 1)
            {
                base.LocalMasterRow["Ma_Bp"] = SDBNull.Value;
                base.LocalMasterRow["Ten_Bp"] = SDBNull.Value;
            }
            if (base.SSInvoiceParameters.AllowContractControl != 1)
            {
                base.LocalMasterRow["Ma_Hd"] = SDBNull.Value;
                base.LocalMasterRow["Ten_Hd"] = SDBNull.Value;
            }
            if (base.SSInvoiceParameters.DefaultActivate == "N")
            {
                base.LocalDetailTable.Rows[0]["Tk"] = base.SSInvoiceParameters.DefaultAccountCode;
                this.UpdateTkParameters(base.LocalDetailTable.Rows[0], true);
                this.UpdateDtParameters(base.LocalDetailTable.Rows[0], true);
            }
            else
            {
                base.LocalDetailTable.Rows[0]["Ma_Dt"] = DBNull.Value;
                base.LocalDetailTable.Rows[0]["Han_Tt"] = DBNull.Value;
            }
            base.OnAdd();
        }

        internal override void OnCopy()
        {
            object obj2 = base.LocalMasterRow["So_Ct"];
            object obj3 = SDBNull.Value;
            base.LocalMasterRow["So_Ct"] = this.oMethod.Cong_So_Ct(AppInstance.Subsidiary, base.InvoiceCode, obj3, base.LocalMasterRow["Ngay_Ct"], obj2);
            base.OnCopy();
        }

        internal override void OnResetControls()
        {
            base.DetailGridBrowser = this.grdDetail;
            int num = 0;
            if (base.SSInvoiceParameters.AllowDepartmentControl != 1)
            {
                num += this.txtMa_Hd.Top - this.txtMa_Bp.Top;
                this.lblMa_Bp.Visible = false;
                this.txtMa_Bp.Visible = false;
                this.txtTen_Bp.Visible = false;
            }
            if (base.SSInvoiceParameters.AllowContractControl != 1)
            {
                num += this.txtMa_Dt.Top - this.txtMa_Hd.Top;
                this.lblMa_Hd.Visible = false;
                this.txtMa_Hd.Visible = false;
                this.txtTen_Hd.Visible = false;
            }
            if (num != 0)
            {
                if (base.SSInvoiceParameters.AllowContractControl == 1)
                {
                    this.lblMa_Hd.Top -= num;
                    this.txtMa_Hd.Top -= num;
                    this.txtTen_Hd.Top -= num;
                }
                this.lblMa_Dt.Top -= num;
                this.txtMa_Dt.Top -= num;
                this.txtTen_Dt.Top -= num;
                this.lblOng_Ba.Top -= num;
                this.txtOng_Ba.Top -= num;
                this.lblDia_Chi.Top -= num;
                this.txtDia_Chi.Top -= num;
                this.lblDien_Giai.Top -= num;
                this.txtDien_Giai.Top -= num;
                this.lblDesc_EN.Top -= num;
                this.txtDesc_EN.Top -= num;
                this.grdDetail.Top -= num;
                this.grdDetail.Height += num;
            }
            if (!base.SSInvoiceParameters.BilingualUsed)
            {
                this.lblDesc_EN.Visible = false;
                this.txtDesc_EN.Visible = false;
                this.txtDien_Giai.Width = (this.txtDesc_EN.Left + this.txtDesc_EN.Width) - this.txtDien_Giai.Left;
                this.txtDien_Giai.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
                this.grdDetail.Columns[13].Visible = false;
            }
            if (!base.SSInvoiceParameters.AllowMultiCurrencies)
            {
                this.grdDetail.Columns[2].Visible = false;
                this.grdDetail.Columns[4].Visible = false;
            }
            if (base.SSInvoiceParameters.AllowDepartmentControl != 2)
            {
                base.DetailGridBrowser.Columns[6].Visible = false;
            }
            if (base.SSInvoiceParameters.AllowContractControl != 2)
            {
                base.DetailGridBrowser.Columns[7].Visible = false;
            }
            if (base.SSInvoiceParameters.AllowCategoryControl != 1)
            {
                base.DetailGridBrowser.Columns[10].Visible = false;
            }
            if (!base.SSInvoiceParameters.AllowProductControl)
            {
                base.DetailGridBrowser.Columns[11].Visible = false;
            }
            if (!base.SSInvoiceParameters.AllowPaymentTerm)
            {
                base.DetailGridBrowser.Columns[9].Visible = false;
            }
            if (base.SSInvoiceParameters.FreeFields <= 0)
            {
                num = base.txtMa_Loai1.Top - this.txtUN_TTien.Top;
                this.lblIL_TTien.Top += num;
                this.txtIL_TTien.Top += num;
                this.lblUN_TTien.Top += num;
                this.txtUN_TTien.Top += num;
                this.lblCt_Di_Kem.Top += num;
                this.txtCt_Di_Kem.Top += num;
                this.lblCt_Di_Kem0.Top += num;
                this.lblPs_No_Nt.Top += num;
                this.txtPs_No_Nt.Top += num;
                this.txtPs_No.Top += num;
                this.lblPs_Co_Nt.Top += num;
                this.txtPs_Co_Nt.Top += num;
                this.txtPs_Co.Top += num;
                base.DetailGridBrowser.Height += num;
            }
            base.OnResetControls();
        }

        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
            if (this.txtOng_Ba != null)
            {
                int num = base.ClientSize.Width - 0xcb;
                this.txtOng_Ba.Width = num / 2;
                this.txtDia_Chi.Left = (this.txtOng_Ba.Left + this.txtOng_Ba.Width) + 0x5c;
                this.txtDia_Chi.Width = num - this.txtOng_Ba.Width;
                this.lblDia_Chi.Left = (this.txtDia_Chi.Left - this.lblDia_Chi.Width) - 6;
                if ((base.SSInvoiceParameters != null) && base.SSInvoiceParameters.BilingualUsed)
                {
                    this.txtDien_Giai.Width = this.txtOng_Ba.Width;
                    this.txtDesc_EN.Left = this.txtDia_Chi.Left;
                    this.txtDesc_EN.Width = this.txtDia_Chi.Width;
                    this.lblDesc_EN.Left = (this.txtDesc_EN.Left - this.lblDesc_EN.Width) - 6;
                }
            }
        }

        protected override bool OnSave()
        {
            if (base.txtNgay_Ps.Value == SDBNull.Value)
            {
                MessageBox.Show("Chưa nhập ngày phát sinh!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (base.txtNgay_Ct.Value == SDBNull.Value)
            {
                MessageBox.Show("Chưa nhập ngày chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (((DateTime) base.txtNgay_Ct.Value) < AppInstance.OpeningDateOfSubEnterprice)
            {
                MessageBox.Show("Ngày chứng từ phải từ ngày " + AppInstance.OpeningDateOfSubEnterprice.ToShortDateString(), AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (((DateTime) base.txtNgay_Ct.Value) <= AppInstance.EndingDateOfSubEnterprice)
            {
                MessageBox.Show("Ngày chứng từ phải từ ngày " + AppInstance.EndingDateOfSubEnterprice.AddDays(1.0).ToShortDateString(), AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (!base.CheckNewRow)
            {
                int num = this.oMethod.CheckInvoiceStatus(AppInstance.Subsidiary, AppInstance.UserName, base.SavedMasterOrder);
                switch (num)
                {
                    case 9:
                    case 7:
                        break;

                    default:
                        if ((base.SSInvoiceParameters.AllowPostInvoice && base.SSInvoiceParameters.AllowLockInvoice) || ((num != 6) && (num != 5)))
                        {
                            if (num == 8)
                            {
                                base.SSInvoiceParameters.ShowInvoiceUsed(base.SavedMasterOrder, base.SSInvoiceParameters.StatusMessage(num));
                                return false;
                            }
                            goto Label_0179;
                        }
                        break;
                }
                MessageBox.Show(base.SSInvoiceParameters.StatusMessage(num), AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
        Label_0179:
            if (!this.Sum())
            {
                MessageBox.Show("Ph\x00e1t sinh nợ v\x00e0 có không c\x00e2n!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            foreach (DataRow row in base.LocalDetailTable.Rows)
            {
                if (((row.RowState != DataRowState.Deleted) && row["Tk_DT"].Equals("C")) && string.IsNullOrEmpty(row["Ma_Dt"].ToString()))
                {
                    BindingSource dataSource = base.DetailGridBrowser.DataSource as BindingSource;
                    dataSource.Position = dataSource.Find(base.DetailOrderString, row["Stt_Nv"]);
                    MessageBox.Show("Ph\x00e1t sinh tr\x00ean tài khoản công\nnợ nhưng chưa chọn đối tượng!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    return false;
                }
            }
            if (this.oMethod.NumberExisted(AppInstance.Subsidiary, base.CheckNewRow, base.SavedMasterOrder, base.InvoiceCode, base.txtNgay_Ct.Value, SDBNull.Value, base.txtSo_Ct.Value) && (MessageBox.Show("Số chứng từ đã tồn tại. C\x00f3 tiếp tục không?", AppInstance.SoftwareName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No))
            {
                if (MessageBox.Show("C\x00f3 muốn tự động tạo số chứng từ không?", AppInstance.SoftwareName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
                {
                    return false;
                }
                object obj2 = base.txtSo_Ct.Value;
                object obj3 = SDBNull.Value;
                base.txtSo_Ct.Value = this.oMethod.Cong_So_Ct(AppInstance.Subsidiary, base.InvoiceCode, obj3, base.LocalMasterRow["Ngay_Ct"], obj2);
            }
            base.DetailGridBrowser.EndEdit();
            base.LocalMasterRow["Ngay_Ps"] = base.txtNgay_Ps.Value;
            base.LocalMasterRow["Ngay_Ct"] = base.txtNgay_Ct.Value;
            base.LocalMasterRow["So_Ct"] = base.txtSo_Ct.Value;
            base.LocalMasterRow["Ma_Tte"] = this.txtMa_Tte.Value;
            base.LocalMasterRow["Ty_Gia"] = this.txtTy_Gia.Value;
            base.LocalMasterRow["Ty_Gia_Ht"] = this.txtTy_Gia.Value;
            base.LocalMasterRow["Ma_Bp"] = this.txtMa_Bp.Value;
            base.LocalMasterRow["Ten_Bp"] = this.txtTen_Bp.Value;
            base.LocalMasterRow["Ma_Hd"] = this.txtMa_Hd.Value;
            base.LocalMasterRow["Ten_Hd"] = this.txtTen_Hd.Value;
            base.LocalMasterRow["Ma_Dt"] = this.txtMa_Dt.Value;
            base.LocalMasterRow["Ten_Dt"] = this.txtTen_Dt.Value;
            base.LocalMasterRow["Ong_Ba"] = this.txtOng_Ba.Value;
            base.LocalMasterRow["Dia_Chi"] = this.txtDia_Chi.Value;
            base.LocalMasterRow["Dien_Giai"] = this.txtDien_Giai.Value;
            base.LocalMasterRow["Desc_EN"] = this.txtDesc_EN.Value;
            base.LocalMasterRow["IL_TTien"] = this.txtIL_TTien.Value;
            base.LocalMasterRow["UN_TTien"] = this.txtUN_TTien.Value;
            base.LocalMasterRow["Ct_Di_Kem"] = this.txtCt_Di_Kem.Value;
            base.LocalMasterRow["TTien_NtN"] = this.txtPs_No_Nt.Value;
            base.LocalMasterRow["TTien_NtC"] = this.txtPs_Co_Nt.Value;
            base.LocalMasterRow["TTien"] = this.txtPs_No.Value;
            base.LocalMasterRow["Ma_Loai1"] = base.txtMa_Loai1.Value;
            base.LocalMasterRow["Ma_Loai2"] = base.txtMa_Loai2.Value;
            base.LocalMasterRow["Ma_Loai3"] = base.txtMa_Loai3.Value;
            return (this.oMethod.Save(base.SSInvoiceParameters.InvoiceHistory, base.CheckNewRow, AppInstance.Subsidiary, AppInstance.UserName, base.LocalMasterRow, base.LocalDetailTable) && base.OnSave());
        }

        internal override void OnShow()
        {
            base.OnShow();
            this.txtMa_Tte.Value = base.LocalMasterRow["Ma_Tte"];
            this.txtTy_Gia.Value = base.LocalMasterRow["Ty_Gia"];
            this.txtMa_Bp.Value = base.LocalMasterRow["Ma_Bp"];
            this.txtTen_Bp.Value = base.LocalMasterRow["Ten_Bp"];
            this.txtMa_Hd.Value = base.LocalMasterRow["Ma_Hd"];
            this.txtTen_Hd.Value = base.LocalMasterRow["Ten_Hd"];
            this.txtMa_Dt.Value = base.LocalMasterRow["Ma_Dt"];
            this.txtTen_Dt.Value = base.LocalMasterRow["Ten_Dt"];
            this.txtOng_Ba.Value = base.LocalMasterRow["Ong_Ba"];
            this.txtDia_Chi.Value = base.LocalMasterRow["Dia_Chi"];
            this.txtDien_Giai.Value = base.LocalMasterRow["Dien_Giai"];
            this.txtDesc_EN.Value = base.LocalMasterRow["Desc_EN"];
            this.txtIL_TTien.Value = base.LocalMasterRow["IL_TTien"];
            this.txtUN_TTien.Value = base.LocalMasterRow["UN_TTien"];
            this.txtCt_Di_Kem.Value = base.LocalMasterRow["Ct_Di_Kem"];
            this.txtPs_No_Nt.Value = base.LocalMasterRow["TTien_NtN"];
            this.txtPs_No.Value = base.LocalMasterRow["TTien"];
            this.txtPs_Co_Nt.Value = base.LocalMasterRow["TTien_NtC"];
            this.txtPs_Co.Value = base.LocalMasterRow["TTien"];
            base.TranCurrencyCode = this.txtMa_Tte.Text;
            if (!base.CheckNewRow)
            {
                base.ExchangeRateOfBook = (decimal) this.txtTy_Gia.Value;
            }
        }

        private bool Sum()
        {
            bool flag = false;
            bool flag2 = false;
            decimal num = 0M;
            decimal num2 = 0M;
            decimal num3 = 0M;
            decimal num4 = 0M;
            decimal num5 = 0M;
            foreach (DataRow row in base.LocalDetailTable.Rows)
            {
                if (((row.RowState == DataRowState.Deleted) || string.IsNullOrEmpty(row["Tk"].ToString())) || (DBNull.Value.Equals(row["Tien_Nt"]) || DBNull.Value.Equals(row["Tien"])))
                {
                    continue;
                }
                if (row["No_Co"].ToString() == "N")
                {
                    num += (decimal) row["Tien_Nt"];
                    num3 += (decimal) row["Tien"];
                }
                else
                {
                    num2 += (decimal) row["Tien_Nt"];
                    num4 += (decimal) row["Tien"];
                }
                if (row["Tk_VAT"].ToString() == "C")
                {
                    num5 += (decimal) row["Tien"];
                    if (row["No_Co"].ToString() == "N")
                    {
                        flag = true;
                        continue;
                    }
                    flag2 = true;
                }
            }
            if (flag && flag2)
            {
                num5 = 0M;
            }
            base.LocalMasterRow["TTien_VAT0"] = num5;
            this.txtPs_No_Nt.Value = num;
            this.txtPs_No.Value = num3;
            this.txtPs_Co_Nt.Value = num2;
            this.txtPs_Co.Value = num4;
            return (num3 == num4);
        }

        private void txtDesc_EN_Validated(object sender, EventArgs e)
        {
            if (this.txtDesc_EN.ValueChanged)
            {
                foreach (DataRow row in base.LocalDetailTable.Rows)
                {
                    if ((row.RowState != DataRowState.Deleted) && (this.txtDesc_EN.OldValue.Equals(row["Desc_EN"]) || (this.txtDesc_EN.OldValue.ToString() == row["Desc_EN"].ToString())))
                    {
                        row["Desc_EN"] = this.txtDesc_EN.Value;
                    }
                }
            }
        }

        private void txtDien_Giai_Validated(object sender, EventArgs e)
        {
            if (this.txtDien_Giai.ValueChanged)
            {
                foreach (DataRow row in base.LocalDetailTable.Rows)
                {
                    if ((row.RowState != DataRowState.Deleted) && (this.txtDien_Giai.OldValue.Equals(row["Dien_Giai"]) || (this.txtDien_Giai.OldValue.ToString() == row["Dien_Giai"].ToString())))
                    {
                        row["Dien_Giai"] = this.txtDien_Giai.Value;
                    }
                }
            }
        }

        private void txtMa_Bp_Validated(object sender, EventArgs e)
        {
            if (this.txtMa_Bp.ValueChanged)
            {
                foreach (DataRow row in base.LocalDetailTable.Rows)
                {
                    if ((row.RowState != DataRowState.Deleted) && (this.txtMa_Bp.OldValue.Equals(row["Ma_Bp"]) || (this.txtMa_Bp.OldValue.ToString() == row["Ma_Bp"].ToString())))
                    {
                        row["Ma_Bp"] = this.txtMa_Bp.Value;
                        row["Ten_Bp"] = this.txtTen_Bp.Value;
                    }
                }
            }
        }

        private void txtMa_Dt_Validated(object sender, EventArgs e)
        {
            if (this.txtMa_Dt.ValueChanged)
            {
                this.txtOng_Ba.Value = this.txtMa_Dt.GetFieldData("Doi_Tac").Equals(DBNull.Value) ? this.txtTen_Dt.Value : this.txtMa_Dt.GetFieldData("Doi_Tac");
                this.txtDia_Chi.Value = this.txtMa_Dt.GetFieldData("Dia_Chi");
                foreach (DataRow row in base.LocalDetailTable.Rows)
                {
                    if (((row.RowState != DataRowState.Deleted) && (this.txtMa_Dt.OldValue.Equals(row["Ma_Dt"]) || (this.txtMa_Dt.OldValue.ToString() == row["Ma_Dt"].ToString()))) && (row["Tk_DT"].ToString() == "C"))
                    {
                        row["Ma_Dt"] = this.txtMa_Dt.Value;
                        row["Ten_Dt"] = this.txtTen_Dt.Value;
                    }
                }
            }
        }

        private void txtMa_Hd_Validated(object sender, EventArgs e)
        {
            if (this.txtMa_Hd.ValueChanged)
            {
                foreach (DataRow row in base.LocalDetailTable.Rows)
                {
                    if ((row.RowState != DataRowState.Deleted) && (this.txtMa_Hd.OldValue.Equals(row["Ma_Hd"]) || (this.txtMa_Hd.OldValue.ToString() == row["Ma_Hd"].ToString())))
                    {
                        row["Ma_Hd"] = this.txtMa_Hd.Value;
                        row["Ten_Hd"] = this.txtTen_Hd.Value;
                    }
                }
            }
        }

        private void txtMa_Tte_Validated(object sender, EventArgs e)
        {
            if (((base.SSInvoiceParameters != null) && (base.LocalMasterRow != null)) && this.txtMa_Tte.ValueChanged)
            {
                base.TranCurrencyCode = this.txtMa_Tte.Text;
                this.txtTy_Gia.Value = base.ExchangeRateOfBook;
                this.is_CurrentRowCurrency = base.TranCurrencyCode;
                this.RowExchangeType = base.ExchangeType;
                this.RowExchangeRateOfBook = base.ExchangeRateOfBook;
                foreach (DataRow row in base.LocalDetailTable.Rows)
                {
                    if ((row.RowState != DataRowState.Deleted) && (this.txtMa_Tte.OldValue.Equals(row["Ma_Tte"]) || (this.txtMa_Tte.OldValue.ToString() == row["Ma_Tte"].ToString())))
                    {
                        row["Ma_Tte"] = this.txtMa_Tte.Value;
                        row["Ty_Gia"] = base.ExchangeRateOfBook;
                        row["Ty_Gia_Ht"] = decimal.Round(base.ExchangeRate, base.ExchangeDecimals);
                        this.Calculate(row);
                    }
                }
                this.Sum();
            }
        }

        private void txtTy_Gia_Validated(object sender, EventArgs e)
        {
            if (this.txtTy_Gia.ValueChanged)
            {
                base.ExchangeRateOfBook = (decimal) this.txtTy_Gia.Value;
                foreach (DataRow row in base.LocalDetailTable.Rows)
                {
                    if ((row.RowState != DataRowState.Deleted) && (this.txtMa_Tte.Value.Equals(row["Ma_Tte"]) || (this.txtMa_Tte.OldValue.ToString() == row["Ma_Tte"].ToString())))
                    {
                        row["Ty_Gia"] = base.ExchangeRateOfBook;
                        row["Ty_Gia_Ht"] = decimal.Round(base.ExchangeRate, base.ExchangeDecimals);
                        this.RowExchangeRateOfBook = base.ExchangeRateOfBook;
                        this.Calculate(row);
                    }
                }
            }
        }

        private void UpdateDtParameters(DataRow po_Row, bool pb_CheckFirst)
        {
            if (!base.SSInvoiceParameters.AllowPaymentTerm || (!po_Row["Tk_KV"].Equals("C") && !po_Row["Tk_DT"].Equals("C")))
            {
                po_Row["Han_Tt"] = DBNull.Value;
            }
            else
            {
                DataRow row = SSDataAccess.SelectDataRow(false, "DMDT", "Ma_Dt", po_Row["Ma_Dt"].ToString(), null);
                if (row != null)
                {
                    if (((po_Row["No_Co"].ToString() == "N") && (row["No_Co"].ToString() != "1")) || ((po_Row["No_Co"].ToString() == "C") && (row["No_Co"].ToString() != "2")))
                    {
                        po_Row["Han_Tt"] = DBNull.Value;
                    }
                    else if (DBNull.Value.Equals(po_Row["Han_Tt"]) && !DBNull.Value.Equals(row["Han_Tt"]))
                    {
                        po_Row["Han_Tt"] = (pb_CheckFirst ? ((DateTime) base.LocalMasterRow["Ngay_Ct"]) : ((DateTime) base.txtNgay_Ct.Value)).Add(new TimeSpan((int) row["Han_Tt"], 0, 0, 0));
                    }
                }
            }
        }

        private void UpdateTkParameters(DataRow po_Row, bool pb_CheckFirst)
        {
            if (DBNull.Value.Equals(po_Row["Tk"]) || string.IsNullOrEmpty(po_Row["Tk"].ToString()))
            {
                if (base.SSInvoiceParameters.AllowDepartmentControl == 0)
                {
                    po_Row["Ma_Bp"] = SDBNull.Value;
                    po_Row["Ten_Bp"] = SDBNull.Value;
                }
                if (base.SSInvoiceParameters.AllowContractControl == 0)
                {
                    po_Row["Ma_Hd"] = SDBNull.Value;
                    po_Row["Ten_Hd"] = SDBNull.Value;
                }
                if (!base.SSInvoiceParameters.AllowPaymentTerm)
                {
                    po_Row["Han_Tt"] = DBNull.Value;
                }
                if (base.SSInvoiceParameters.AllowCategoryControl == 0)
                {
                    po_Row["Ma_Km"] = SDBNull.Value;
                    po_Row["Ten_Km"] = SDBNull.Value;
                }
                if (!base.SSInvoiceParameters.AllowProductControl)
                {
                    po_Row["Ma_Sp"] = SDBNull.Value;
                    po_Row["Ten_Sp"] = SDBNull.Value;
                }
            }
            else
            {
                DataRow row = SSDataAccess.SelectDataRow(false, "DMTK", "Tk", po_Row["Tk"].ToString(), null);
                if (row == null)
                {
                    if (base.SSInvoiceParameters.AllowDepartmentControl == 0)
                    {
                        po_Row["Ma_Bp"] = SDBNull.Value;
                        po_Row["Ten_Bp"] = SDBNull.Value;
                    }
                    if (base.SSInvoiceParameters.AllowContractControl == 0)
                    {
                        po_Row["Ma_Hd"] = SDBNull.Value;
                        po_Row["Ten_Hd"] = SDBNull.Value;
                    }
                    if (!base.SSInvoiceParameters.AllowPaymentTerm)
                    {
                        po_Row["Han_Tt"] = DBNull.Value;
                    }
                    if (base.SSInvoiceParameters.AllowCategoryControl == 0)
                    {
                        po_Row["Ma_Km"] = SDBNull.Value;
                        po_Row["Ten_Km"] = SDBNull.Value;
                    }
                    if (!base.SSInvoiceParameters.AllowProductControl)
                    {
                        po_Row["Ma_Sp"] = SDBNull.Value;
                        po_Row["Ten_Sp"] = SDBNull.Value;
                    }
                }
                else
                {
                    po_Row["Tk_NT"] = row["Tk_NT"];
                    po_Row["Tk_BP"] = row["Tk_BP"];
                    po_Row["Tk_HD"] = row["Tk_HD"];
                    po_Row["Tk_DT"] = row["Tk_DT"];
                    po_Row["Tk_KM"] = row["Tk_KM"];
                    po_Row["Tk_GT"] = row["Tk_GT"];
                    po_Row["Tk_KV"] = row["Tk_KV"];
                    po_Row["Tk_VAT"] = row["Tk_VAT"];
                    if ((base.SSInvoiceParameters.AllowDepartmentControl == 0) || !row["Tk_BP"].Equals("C"))
                    {
                        po_Row["Ma_Bp"] = SDBNull.Value;
                        po_Row["Ten_Bp"] = SDBNull.Value;
                    }
                    else if (DBNull.Value.Equals(po_Row["Ma_Bp"]) || string.IsNullOrEmpty(po_Row["Ma_Bp"].ToString()))
                    {
                        po_Row["Ma_Bp"] = pb_CheckFirst ? base.LocalMasterRow["Ma_Bp"] : this.txtMa_Bp.Value;
                        po_Row["Ten_Bp"] = pb_CheckFirst ? base.LocalMasterRow["Ten_Bp"] : this.txtTen_Bp.Value;
                    }
                    if ((base.SSInvoiceParameters.AllowContractControl == 0) || !row["Tk_HD"].Equals("C"))
                    {
                        po_Row["Ma_Hd"] = SDBNull.Value;
                        po_Row["Ten_Hd"] = SDBNull.Value;
                    }
                    else if (DBNull.Value.Equals(po_Row["Ma_Hd"]) || string.IsNullOrEmpty(po_Row["Ma_Hd"].ToString()))
                    {
                        po_Row["Ma_Hd"] = pb_CheckFirst ? base.LocalMasterRow["Ma_Hd"] : this.txtMa_Hd.Value;
                        po_Row["Ten_Hd"] = pb_CheckFirst ? base.LocalMasterRow["Ten_Hd"] : this.txtTen_Hd.Value;
                    }
                    if (!row["Tk_DT"].Equals("C"))
                    {
                        po_Row["Ma_Dt"] = SDBNull.Value;
                        po_Row["Ten_Dt"] = SDBNull.Value;
                    }
                    else if (DBNull.Value.Equals(po_Row["Ma_Dt"]) || string.IsNullOrEmpty(po_Row["Ma_Dt"].ToString()))
                    {
                        po_Row["Ma_Dt"] = pb_CheckFirst ? base.LocalMasterRow["Ma_Dt"] : this.txtMa_Dt.Value;
                        po_Row["Ten_Dt"] = pb_CheckFirst ? base.LocalMasterRow["Ten_Dt"] : this.txtTen_Dt.Value;
                    }
                    this.UpdateDtParameters(po_Row, pb_CheckFirst);
                    if ((base.SSInvoiceParameters.AllowCategoryControl == 0) || !row["Tk_KM"].Equals("C"))
                    {
                        po_Row["Ma_Km"] = SDBNull.Value;
                        po_Row["Ten_Km"] = SDBNull.Value;
                    }
                    if (!base.SSInvoiceParameters.AllowProductControl || !row["Tk_GT"].Equals("C"))
                    {
                        po_Row["Ma_Sp"] = SDBNull.Value;
                        po_Row["Ten_Sp"] = SDBNull.Value;
                    }
                }
            }
        }

        private object CurrentRowCurrency
        {
            get
            {
                return this.is_CurrentRowCurrency;
            }
            set
            {
                if (!this.is_CurrentRowCurrency.Equals(value) || (this.is_CurrentRowCurrency.ToString() != value.ToString()))
                {
                    this.is_CurrentRowCurrency = value;
                    if (this.is_CurrentRowCurrency.ToString() == AppInstance.DefaultCurrency)
                    {
                        this.RowExchangeRateOfBook = 1M;
                        this.RowExchangeType = true;
                    }
                    else if (base.SSInvoiceParameters.AllowMultiCurrencies)
                    {
                        if (this.is_CurrentRowCurrency.ToString() != base.TranCurrencyCode)
                        {
                            bool flag = true;
                            this.RowExchangeRateOfBook = base.SSInvoiceParameters.SSInvoiceMethod.ExchangeRate(this.is_CurrentRowCurrency, ref flag);
                            this.RowExchangeType = flag;
                        }
                        else
                        {
                            this.RowExchangeType = this.RowExchangeType;
                            this.RowExchangeRateOfBook = base.ExchangeRateOfBook;
                        }
                    }
                    else
                    {
                        this.RowExchangeType = base.ExchangeType;
                        this.RowExchangeRateOfBook = base.ExchangeRateOfBook;
                    }
                }
            }
        }

        private decimal RowExchangeRate
        {
            get
            {
                if (!this.RowExchangeType)
                {
                    return (1M / this.RowExchangeRateOfBook);
                }
                return this.RowExchangeRateOfBook;
            }
        }

        private decimal RowExchangeRateOfBook
        {
            get
            {
                return this.ii_RowExchangeRateOfBook;
            }
            set
            {
                if (this.ii_RowExchangeRateOfBook != value)
                {
                    this.ii_RowExchangeRateOfBook = value;
                }
            }
        }

        private bool RowExchangeType
        {
            get
            {
                return this.ib_RowExchangeType;
            }
            set
            {
                if (this.ib_RowExchangeType != value)
                {
                    this.ib_RowExchangeType = value;
                }
            }
        }
    }
}

